痕迹未显示

时间:2019-10-31 08:18:45

标签: plotly

plotly版本4.2.1,python 3.7.3

尝试通过下面的简单示例进行图解探索,但是该图解显示为无痕迹。(我注意到两个轴的限制都不会随着不同的数据范围而改变)

import numpy as np
import plotly.graph_objs as go

x = np.arange(10)    #np.linspace(0,1,100)
y = x**2             #np.random.randn(100)


fig = go.Figure()
fig.add_trace = [go.Scatter(x=x, y=y+5,
               mode='markers',  name = 'marker',)]
fig.add_trace = [go.Scatter(x=x, y=y,
               mode='lines',  name = 'mylines')]

fig.update_layout(title='line charts',)
fig.show()

1 个答案:

答案 0 :(得分:0)

fig.add_trace()不是可以分配值的变量。该功能可以使其他元素中的go.Scatter()作为参数。

更正的代码:

import numpy as np
import plotly.graph_objs as go

x = np.arange(10)    #np.linspace(0,1,100)
y = x**2             #np.random.randn(100)


fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y+5,
               mode='markers',  name = 'marker'))

fig.add_trace(go.Scatter(x=x, y=y,
               mode='lines',  name = 'mylines'))

fig.update_layout(title='line charts',)
fig.show()

情节:

enter image description here