以下代码用于获取上述内容
from random import randint
import plotly.graph_objects as go
x1 = [randint(0, 9) for p in range(0, 10)]
x2 = [randint(0, 9) for p in range(0, 10)]
x3 = [randint(0, 9) for p in range(0, 10)]
time=list(range(0, len(x1)))
fig = go.Figure()
fig.add_trace(go.Scatter(x=time, y=x1,
mode='lines',
name='X1'))
fig.add_trace(go.Scatter(x=time, y=x2,
mode='lines',
name='X2'))
fig.add_trace(go.Scatter(x=time, y=x3,
mode='lines',
name='X3'))
但是,为了使代码更高效,我尝试了从这个链接获得的类似这样的东西
data=[x1,x2,x3] ##这可能是错误的
for i in range(0,2):
trace = go.Scatter( x = times,
y = data[:, i],
mode = 'markers+lines'
)
每当我尝试使用 for 循环使用 plotly 绘制图形时,什么都没有出现。
感谢任何帮助。谢谢
杨魅力
相关分类