情节:如何绘制多个y轴?

时间:2019-11-28 03:56:52

标签: python graph plotly

这是我的代码,但是有问题。问题之一是它的直线很奇怪,没有价值(图中蓝色圆圈)。我的想法是,是因为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

1 个答案:

答案 0 :(得分:1)

我几乎可以向您保证问题是x轴数据的格式。您可能对某些观察结果有一种奇怪的格式,或者只是将错误的数字直接分配给错误的索引。已在此处提出并回答了一个相关的问题:How to disable trendline in plotly.express.line?如果您查看那里的绘图,您会看到相同的直线,看上去似乎是发疯的:

enter image description here