Reputation: 481
I don't understand why this snippet of code does not work. The data is fictional, I just want to be able to make time-series visualization with plotly.
This module once worked for me in a Kaggle kernel :
https://www.kaggle.com/aubertsigouin/organizing-macrohistorical-datasets/data
Curiously, I am not able to make it work again. It says « AttributeError: module 'plotly' has no attribute 'plotly' ».
Any tips ?
import plotly
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import init_notebook_mode, plot, iplot
init_notebook_mode()
import pandas as pd
import numpy as np
data = []
array_of_time = pd.to_datetime(np.arange('2013-01-01', '2013-03-01', dtype='datetime64[M]'))
raw_data = [[20,29], [30,33]]
trace_1 = go.Scatter(
x=array_of_time,
y=raw_data[0],
name = 'data_1',
line = dict(color = '#aeb9ba'),
opacity = 0.8
)
trace_2 = go.Scatter(
x=array_of_time,
y=raw_data[1],
name = 'data_2',
line = dict(color = '#ffd800'),
opacity = 0.8
)
data.append(trace_1)
data.append(trace_2)
layout = dict(
title = 'Exemple de titre',
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(
count=1,
label='1m',
step='month',
stepmode='backward'
),
dict(
count=6,
label='6m',
step='month',
stepmode='backward'
),
dict(
step='all'
)
]
)
),
rangeslider=dict(),
type='date'
)
)
fig = dict(data=data, layout=layout)
iplot(fig, filename = 'graph_1.html')
It gives me the following error :
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-59-81b77c8cb926> in <module>()
53
54 fig = dict(data=data, layout=layout)
---> 55 iplot(fig, filename = 'graph_1.html')
~\Anaconda3\lib\site-packages\plotly\offline\offline.py in iplot(figure_or_data, show_link, link_text, validate, image, filename, image_width, image_height, config)
342 cls=plotly.utils.PlotlyJSONEncoder))
343
--> 344 fig = {'data': data, 'layout': layout}
345 if frames:
346 fig['frames'] = frames
~\Anaconda3\lib\site-packages\plotly\offline\offline.py in _plot_html(figure_or_data, config, validate, default_width, default_height, global_requirejs)
206 'plotGlPixelRatio',
207 'setBackground',
--> 208 'topojsonURL'
209 )
210
AttributeError: module 'plotly' has no attribute 'plotly'
Upvotes: 6
Views: 44105
Reputation: 9
I had to first install plotly using
pip install plotly==5.10.0 in the command prompt
Restart Spyder after installation of plotly5.10.0
Then,
import plotly.express as plt
Upvotes: 0
Reputation: 1
Starting in plotly version 4.0, all Chart Studio related functionality has been moved to the chart_studio library.
To install Chart Studio's python package, use:
pip install chart_studio
Set your credentials as below.
First:
import chart_studio
Finally:
chart_studio.tools.set_credentials_file(
username='xxxxxxxxx',
api_key='xxxxxxxx'
)
Upvotes: -3
Reputation: 99
Firstly I suggest to install chart_studio(if you are using anaconda install in conda promt)
pip install chart-studio
Then in your jupyter notebook import plotly with the following way:
import chart_studio.plotly as py
Upvotes: -1
Reputation: 61
Try import plotly.plotly
.
I recommend giving it an alias like import plotly.plotly as plt
.
Essentially in plotly.plotly
, the first one is calling the plotly
package and the second one after .
is calling the function plotly from the package.
Edit: Please do let me know, if it worked for you or not.
Upvotes: 6