gpt4 book ai didi

python - 痕迹未显现

转载 作者:行者123 更新时间:2023-12-01 07:00:43 25 4
gpt4 key购买 nike

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()

最佳答案

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()

plotly :

enter image description here

关于python - 痕迹未显现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58639248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com