【问题标题】:KeyError: 'plotly_domain' when using plotly to do scatter plot in pythonKeyError:'plotly_domain'在python中使用plotly做散点图时
【发布时间】:2016-04-28 01:17:56
【问题描述】:

我正在使用 plotly 来做散点图。图是在我的账号上生成的,但是终端还是报错:

Traceback (most recent call last):
File "IEORE4709HW1.py", line 106, in <module>
py.iplot(data, filename='basic-scatter')
File "/Library/Python/2.7/site-packages/plotly/plotly/plotly.py", line 175, in iplot
return tools.embed(url, **embed_options)
File "/Library/Python/2.7/site-packages/plotly/tools.py", line 412, in embed
!= session.get_session_config()['plotly_domain']):
KeyError: 'plotly_domain'

我的代码是:

import urllib2
import numpy as np

import plotly.plotly as py
py.sign_in('halblooline', 'j90503v8gq')
import plotly.graph_objs as go
import numpy as np

N = 1000
random_x = np.random.randn(N)
random_y = np.random.randn(N)

# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y,
    mode = 'markers'
)

data = [trace]

# Plot and embed in ipython notebook!
py.iplot(data, filename='basic-scatter')

# or plot with: plot_url = py.plot(data, filename='basic-line')

任何人都可以帮助我吗?非常感谢。

【问题讨论】:

  • 您是在 ipython 笔记本中执行此操作吗?如果没有,请使用plot() 命令,如下面的答案所述。

标签: python plot plotly keyerror


【解决方案1】:

使用 py.plot 代替 py.iplot。试一试。

【讨论】:

  • 这很好用。 iplot 适用于 Jupyter 笔记本(以前的 IPython 笔记本)。
猜你喜欢
  • 2016-12-02
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
  • 2020-07-27
  • 2021-11-04
相关资源
最近更新 更多