gpt4 book ai didi

python - Plotly:如何绘制多个 y 轴?

转载 作者:行者123 更新时间:2023-12-01 06:49:35 39 4
gpt4 key购买 nike

这是我的代码。但是它有一个问题。问题之一是它有一条奇怪的没有值(value)的直线(图中的蓝色圆圈)。我的想法是,是因为 csv 文件吗?

我的 csv 数据如下所示:

report_number|pow_error|cw_frequency|specification
1 0.5 10 1
1 0.2 20 1
2 0.8 10 1

import plotly.graph_objects as go

df = pd.read_csv(r"C:\Users\Downloads\Export\C1.csv")
y=df.power_error

trace0=go.Scatter(x=df.cw_frequency,
y=df.power_error,

mode='lines',
name='power_error',
line=dict(color='firebrick',dash='solid')
)

trace1=go.Scatter(x=df.cw_frequency,
y=df.specification+y,
mode='lines',
line=dict(color='orange', width=0.5,dash='dash'),
name='specification',
text="Report Number:"+df.report_number)

trace2=go.Scatter(x=df.cw_frequency, y=y-df.specification,
mode='lines',
line=dict(color='orange', width=0.5,dash='dash'),
name='specification',
text="Report Number:"+df.report_number)

mdata=go.Data([trace0,trace1,trace2])

layout=dict(
title="Maximum Output Power",
xaxis_title="Frequency",
yaxis_title="Maximum Output Power dBM",
font=dict(
family="Courier New, monospace",
size=11,
color="#7f7f7f")
)

fig=dict(data=mdata,layout=layout)

iplot(fig)

enter image description here

我的预期结果如下: enter image description here

最佳答案

我几乎可以向您保证问题出在 x 轴数据的格式上。您的某些观察结果要么采用奇怪的格式,要么直接将错误的数字分配给错误的索引。此处已提出并回答了相关问题:How to disable trendline in plotly.express.line?如果您看一下那里的图,您会看到似乎突然出现的同一条直线:

enter image description here

关于python - Plotly:如何绘制多个 y 轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59081527/

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