How to save plotly offline figure inside jupyter notebook? - python

I am using plotly to plot figure inside jupyter notebook. After re-opening jupyter notebook, all the figures are not shown. I am wondering if it is possible to save the figures inside the notebook after being saved, just like using matplotlib or seaborn. Thanks
import plotly.graph_objects as go
import plotly
from plotly.offline import init_notebook_mode, iplot
from plotly.subplots import make_subplots
#fig=make_subplots(specs=[[{"secondary_y": True}]])
fig=go.Figure()
fig.add_scatter(x=differenced_data.index[-1*n_steps:], y=test.values,name='test data',mode='lines+markers',marker=dict(color='green',size=5)) #mode='markers','lines','lines+markers'
iplot(fig)

Related

How to display plotly as svg in GitHub and interactive plotly while in local?

My goal is to display plotly charts in GitHub (interactive or not). The reason that I switch to Plotly instead of using matplotlib.pyplot or pandas.Series.plot is that it offers you interactive charts.
However, after pushing the .ipynb file to GitHub. I noticed that the charts are not showing up.
What I've tried:
# fix plotly is not showing in github.
# if you want to have interactive plotly, use `fig.show("notebook_connected")`
import plotly.io as pio
pio.renderers.default = "svg"
The problem is that the charts become not interactive even in local.
Changing it to pio.renderers.default = "svg+notebook", the charts will be interactive in local. But it won't show in GitHub.

Plotly maps not showing in Jupyter Notebook in VS Code

stacks!
I'm trying to plot a graph using plotly, in Python. Specifically:
Plot: Maps, Bubblemaps, Choropleth..
Python: 3.9.6
Plotly: 4.01
Jupyter Notebook: 7.26
Env Manager: miniconda3
IDE: Ms. Visual Studio Code
I tried to run a code like this:
import plotly
import plotly.offline as pyo
pyo.init_notebook_mode()
import plotly.graph_objs as go
import plotly.express as ex
df = ex.data.gapminder().query("year==2007")
fig = ex.choropleth(df, locations="iso_alpha",
color="lifeExp", # lifeExp is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=ex.colors.sequential.Plasma)
which is not my project code, just the example code of Plotly Map that I found on Plotly website (https://plotly.com/python/choropleth-maps/), but it's not showing anything.
P.S: I've tried to install plotly Jupyterlab dependencies from conda, i've also tried to use offline plotly but still nothing comes up. (Only the plot canvas and legend, the map is missing). Although, when I tried to make a bar chart it works. Help me masters!!!!!

Why Plotly is not working on Jupyter Lab?

I had to update my Macbook Air's iOS (Catalina), since I updated to this iOS's version, plotly stop working on my Jupyter-lab's enviroment.
I already followed the Getting Started's steps showed on plotly website:
$ pip install jupyterlab==1.2 "ipywidgets>=7.5"
When I run a random example, it shows an empty white block:
The libraries that I was importing (The ones that worked before):
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import cufflinks as cf
from plotly.offline import download_plotlyjs,init_notebook_mode, plot,iplot
import plotly.graph_objs as go
init_notebook_mode(connected=True)
cf.go_offline()
%matplotlib inline
You need to have the relevant JupyterLab extensions installed, as per our Getting Started guide here: https://plot.ly/python/getting-started/
If you're having trouble, here is our troubleshooting guide: https://plot.ly/python/troubleshooting/

Issue with interactive plot on matplotlib within jupyter notebook

I have this issue after selecting the zoom button on the interactive toolbar beneath the plot. When I click to draw a rectangle (for zooming in to), black lines appears. This only happens in the bottom and right-most side of the plot.
I am using Python 3.6.4 and the following packages:
matplotlib (2.1.2)
jupyter (1.0.0)
Code to reproduce issue (within jupyter notebook):
import numpy as np
from numpy.random import random
import matplotlib.pyplot as plt
%matplotlib notebook
plt.plot(random(100), random(100), '.')

IOPub data rate exceeded error in Jupyter Notebook

I was trying to make cufflinks offline, but it is showing an error in the Jupyter Notebook. Jupyter was able to execute every cell except the last line of code (cf.go_offline()).
Can anyone fix it? For the first time, I am trying out this cufflinks library. Is there any issue with the version of the package, or is it any other issue?
Input:
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
import cufflinks as cf
cf.go_offline()
Output:
warning message-
IOPub data rate exceeded.The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable`--NotebookApp.iopub_data_rate_limit

Categories