Jovis ch
Jovis ch

Reputation: 45

Plotly: How to plot a multiple y axis?

This is my code.However it has a problem. One of problems is it has a strange straight line without value(blue circle in pic). My thought is, is it because of csv file?

my csv data is something like below:

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

My expected out is as below: enter image description here

Upvotes: 1

Views: 413

Answers (1)

vestland
vestland

Reputation: 61104

I can pretty much guarantee you that the problem is the formatting of the x-axis data. You've either got a weird format for some of your observations, or just straight up wrong numbers assigned to the wrong index. A related question has been asked and answered here: How to disable trendline in plotly.express.line? If you take a look at the plot there, you'll see the same straight line that seems to appear out of the blue:

enter image description here

Upvotes: 1

Related Questions