Reputation: 4208
I am quite struggling with plotly offline mode in jupyter notebook. I used to use import plotly.plotly as py and then use py.offline.plot(). Now it tells me plotly.plotly is depreciated and want me to use chart_studio.plotly. Now I don't know how to use offline mode for chart_studio.plot. I either got an error of Authentication is required or chart_studio doesn't have offline mode. I just want to plot some figures in jupyter notebook using plotly. How can I fix the issue? Thanks
import chart_studio.plotly as py
from chart_studio.grid_objs import Grid, Column
import plotly.figure_factory as FF
import pandas as pd
import time
import pickle
filename_pickle='dataset.pkl'
try:
dataset=pd.read_pickle(filename_pickle)
except FileNotFoundError:
url = 'https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv'
dataset = pd.read_csv(url)
dataset.to_pickle(filename_pickle)
table = FF.create_table(dataset.head(10))
#py.iplot(table, filename='animations-gapminder-data-preview')
py.offline.iplot(table)
Previously: I use plotly.plotly
import plotly.plotly as py
from plotly.grid_objs import Grid, Column
from plotly.tools import FigureFactory as FF
# chart_studio is for online mode only
# import chart_studio.plotly as py
# from chart_studio.grid_objs import Grid, Column
# import plotly.figure_factory as FF
import pandas as pd
import time
import pickle
filename_pickle='dataset.pkl'
try:
dataset=pd.read_pickle(filename_pickle)
except FileNotFoundError:
url = 'https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv'
dataset = pd.read_csv(url)
dataset.to_pickle(filename_pickle)
table = FF.create_table(dataset.head(10))
#py.iplot(table, filename='animations-gapminder-data-preview')
py.offline.iplot(table)
then I got an error of
ImportError:
The plotly.plotly module is deprecated,
please install the chart-studio package and use the
chart_studio.plotly module instead.
Upvotes: 0
Views: 3722
Reputation: 1471
You just have to import plotly
not plotly.plotly
and call the offline.iplot
with your chart at the parameter as shown in my example:
import plotly
import plotly.graph_objs as go
data = [go.Scatter(x=[1,2,3,4], y=[1,2,4,3])]
plotly.offline.iplot(data)
Upvotes: 2