我有一些旧代码,以类似的方式在同一张图上绘制许多线段
import plotly.plotly as py
import plotly.graph_objs as go
data = [regtimes, avg5times]
py.iplot(data, filename='basic-line')
,这将在同一图上绘制两条线。我试图再次使用它,它说plotly.plotly已弃用。现在我有类似的东西
individualtimes = go.Scatter(
y = times,
x = x1,
)
test = go.Scatter(
y2=[1, 1, 5],
x2=x1
)
data = [individualtimes,test]
fig = go.Figure(data=data)
fig.show()
有没有一种方法可以使用fig.show这样绘制多条线?谢谢!
答案 0 :(得分:0)
我找到了答案!更改为使用add_trace,然后显示该图。密谋使用
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
# Create traces
fig = go.Figure()
fig.add_trace(go.Scatter(x=random_x, y=random_y0,
mode='lines',
name='lines'))
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='markers', name='markers'))
fig.show()
其余的内容可以在here中找到。