gpt4 book ai didi

python - 属性错误 : module 'plotly' has no attribute 'plotly'

转载 作者:太空狗 更新时间:2023-10-30 01:11:22 25 4
gpt4 key购买 nike

我不明白为什么这段代码不起作用。数据是虚构的,我只是想能够用plotly做时间序列可视化。

这个模块曾经在 Kaggle 内核中为我工作:

https://www.kaggle.com/aubertsigouin/organizing-macrohistorical-datasets/data

奇怪的是,我无法让它再次工作。它说 « AttributeError: module 'plotly' has no attribute 'plotly' »。

有什么建议吗?

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')

它给了我以下错误:

---------------------------------------------------------------------------
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'

最佳答案

尝试import plotly.plotly

我建议给它一个别名,比如 import plotly.plotly as plt

本质上,在plotly.plotly中,第一个是调用plotly包,第二个是在.之后调用函数plotly from包。

编辑:请务必让我知道它是否对您有用。

关于python - 属性错误 : module 'plotly' has no attribute 'plotly' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51251188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com