python - python plotly : PlotlyError

标签 python plotly

我正在学习Python,地址:https://plot.ly/python/offline/ 当我尝试这个例子时:

import plotly.plotly as py 
fig = py.get_figure('https://plot.ly/~jackp/8715', raw=True)
iplot(fig)

答案给了我这个错误:

---------------------------------------------------------------------------
PlotlyError                               Traceback (most recent call last)
<ipython-input-13-71d04f672671> in <module>()
      1 import plotly.plotly as py
      2 
----> 3 fig = py.get_figure('https://plot.ly/~jackp/8715', raw=True)
      4 iplot(fig)

D:\ProgramData\Anaconda2\lib\site-packages\plotly\plotly\plotly.pyc in get_figure(file_owner_or_url, file_id, raw)
    407                 "'{1}'."
    408                 "\nRun help on this function for more information."
--> 409                 "".format(url, plotly_rest_url))
    410         head = plotly_rest_url + "/~"
    411         file_owner = url.replace(head, "").split('/')[0]

PlotlyError: Because you didn't supply a 'file_id' in the call, we're assuming you're trying to snag a figure from a url. You supplied the url, 'https://plot.ly/~jackp/8715', we expected it to start with 'https://plotly.your-company.com'.
Run help on this function for more information.

我不知道错误在哪里,我认为可能是url https://plotly.your-company.com坏了。

最佳答案

这是recommended获取凭据文件的方法。遵循教程时充分阅读示例总是有帮助的,正确设置您的环境也很重要。

  1. here并创建一个帐户
  2. here并获取 API key
  3. 在尝试获取图形之前将其输入代码中(必须导入plotly以及plotly.plotly):

plotly.tools.set_credentials_file(username='username-from-step-1', api_key='key-you-copied-from-step-2')

此行将授予您访问权限

编辑:iplot(fig)如果您收到新错误,则仅适用于某些设置。尝试将该行替换为 py.plot(fig)

关于python - python plotly : PlotlyError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45879759/

相关文章:

javascript - 使用 Plotly.js 动态创建/删除/重新设计图形的最佳方式?

python - crontab 不会运行 os.system python 命令

r - 在 plot_ly 中覆盖散点区域

python - Opencv 找不到所有轮廓

python - 通过网络掩码删除重复的 IP 地址

python - 在嵌入式绘图图表上启用滚轮缩放

r - 用plotly制作点状网格线

r - 线条下方的3D填充

python - 计算时间序列中两点之间的角度

python - 在两个 python 装饰器之间传递变量