Plotly Y axis on both Left and Right?

Is there an easy way to show the y axis for a plotly chart on both the right and the left side? Would just be more convenient to look at time series data if I could have it readily accessible on both sides if that makes sense. Thanks! :slight_smile:

1 Like

Hi @dash-beginner

AFAIK the only way to add a secondary Y-axis is by using the make_subplots function as show in the examples here - Multiple axes in Python (plotly.com)

So what I need is the time series to use the same y axis, but for the same axis to appear on both the left and right side of the graph. Is that possible without using a workaround of having a secondary axis and just replotting all of the timeseries on that secondary axis? (Does that make sense - I just need two of the same axis, one on the left, one on the right).

@dash-beginner
I believe that’s not possible, you’ll have to plot your timeseries data on both the axis.

Ah that’s what I figured - hopefully that’s a feature that’s included in a future update and until then I’ll use that workaround. Thanks! :slight_smile:

1 Like

@dash-beginner, you can try this work around. Instead of plotting all the points for y2 axis, just plot 2 points(min and max).
I modified the sample from the documentation below.

fig = go.Figure()
x=[1, 2, 3]
y=[4, 5, 6]

fig.add_trace(go.Scatter(
    x=x,
    y=y,
    name="yaxis1 data"
))

fig.add_trace(go.Scatter(
    x=[min(x), max(x)], 
    y=[min(y), max(y)],
    name="yaxis2 data",
    yaxis="y2"
))

fig.update_layout(
    xaxis=dict(
        domain=[0.3, 0.7]
    ),
    yaxis=dict(
        title="yaxis title",
        titlefont=dict(
            color="#1f77b4"
        ),
        tickfont=dict(
            color="#1f77b4"
        )
    ),
    yaxis2=dict(
        title="yaxis2 title",
        titlefont=dict(
            color="#ff7f0e"
        ),
        tickfont=dict(
            color="#ff7f0e"
        ),
        anchor="free",
        overlaying="y",
        side="right",
        position=0.7
    )
)

fig.show()
2 Likes

Is there a way of achieving the same result for an imshow plot (which does not accept a yaxis argument)?