我不能在python上使用plotly

9rnv2umw  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(179)

我试图用python重现plotly网站上的一个示例。这是:

import plotly.graph_objects as go

# Create random data with numpy

import numpy as np
np.random.seed(1)

N = 100
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N) + 5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N) - 5

fig = go.Figure()

# Add traces

fig.add_trace(go.Scatter(x=random_x, y=random_y0,
                    mode='markers',
                    name='markers'))
fig.add_trace(go.Scatter(x=random_x, y=random_y1,
                    mode='lines+markers',
                    name='lines+markers'))
fig.add_trace(go.Scatter(x=random_x, y=random_y2,
                    mode='lines',
                    name='lines'))

fig.show()

但它不起作用。首先我犯了这个错误:

----> 1 import plotly.graph_objects as go
      2 
      3 # Create random data with numpy
      4 import numpy as np
      5 np.random.seed(1)

ModuleNotFoundError: No module named 'plotly.graph_objects'

所以我试过了 from plotly import graph_objs as go 相反,只是为了获得:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-320177ebffca> in <module>
     16 fig.add_trace(go.Scatter(x=random_x, y=random_y0,
     17                     mode='markers',
---> 18                     name='markers'))
     19 fig.add_trace(go.Scatter(x=random_x, y=random_y1,
     20                     mode='lines+markers',

TypeError: 'NoneType' object is not callable

我做错了什么?
编辑
看来一定是这样 graph_objs 而不是 graph_objects 但是错误 TypeError: 'NoneType' object is not callable 仍然出现。。。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题