gpt4 book ai didi

python - 为什么 plotly.offline.iplot( {'x' : [1, 2, 3], 'y' : [5, 2, 7]}) 不起作用?

转载 作者:行者123 更新时间:2023-11-28 19:15:24 25 4
gpt4 key购买 nike

全新的(今天)plotly (Python) 并按照我的方式完成示例和概述。

plotly.offline.iplot 的方法签名声明:

figure_or_data -- a plotly.graph_objs.Figure or plotly.graph_objs.Data or
dict or list that describes a Plotly graph.
See https://plot.ly/python/ for examples of
graph descriptions.

那么为什么它不接受标题中的字典呢?

PlotlyError                               Traceback (most recent call last)
<ipython-input-34-dc2bdcac2527> in <module>()
----> 1 plotly.offline.iplot({'x': [1, 2, 3], 'y': [5, 2, 7]})

/Users/Pyderman/anaconda/lib/python2.7/site-packages/plotly/offline/offline.pyc in iplot(figure_or_data, show_link, link_text, validate)
104
105 from IPython.display import HTML, display
--> 106 figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)
107
108 width = figure.get('layout', {}).get('width', '100%')

/Users/Pyderman/anaconda/lib/python2.7/site-packages/plotly/tools.pyc in return_figure_from_figure_or_data(figure_or_data, validate_figure)
1412 "plot option.\nHere's why you're "
1413 "seeing this error:\n\n{0}"
-> 1414 "".format(err))
1415 if not figure['data']:
1416 raise exceptions.PlotlyEmptyDataError(

PlotlyError: Invalid 'figure_or_data' argument. Plotly will not be able to properly parse the resulting JSON. If you want to send this 'figure_or_data' to Plotly anyway (not recommended), you can set 'validate=False' as a plot option.
Here's why you're seeing this error:

'y' is not allowed in 'figure'

Path To Error: ['y']

Valid attributes for 'figure' at path [] under parents []:

['layout', 'data']

Run `<figure-object>.help('attribute')` on any of the above.
'<figure-object>' is the object at []

为什么字典必须包含在列表中:

plotly.offline.iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}])

最佳答案

如果您提供一个字典,它假设您输入的是一个图形,如果您输入一个列表,它假设您输入的是数据Data 是一个列表,因为您可以在一个图中包含多个序列。例如

提供数据(注意,两行):

plotly.offline.iplot([
{'x': [1, 2, 3], 'y': [5, 2, 7]},
{'x': [1, 2, 3], 'y': [1, 2, 3])}])

等效的,但提供了一个图形:

plotly.offline.iplot({
'data': [
{'x': [1, 2, 3], 'y': [5, 2, 7]},
{'x': [1, 2, 3], 'y': [1, 2, 3])}]
#Could put layout, etc... here
})

关于python - 为什么 plotly.offline.iplot( {'x' : [1, 2, 3], 'y' : [5, 2, 7]}) 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34191028/

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