Can Subplot support multiple y-axes?

@empet I just tried for an embarrassing amount of time to get it working based on the plotly docs (https://plotly.com/python/multiple-axes/), but couldn’t figure it out.

My understanding is that if you want e.g. three Y-axis on the second row subplot, you have to create a figure with four subplots, then tell plotly through the ‘overlaying’ figure.layout parameter that you want to display the third and fourth subplots over the top of the second one. Then you have to tell plotly through some magic usage of the ‘autoshift’ parameter that the axis labels shouldn’t overlay each other. Here is a minimal example:

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = go.Figure()

fig = make_subplots(rows=4, cols=1) #, specs=[[{"secondary_y": True}]]*4)

fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6], name="yaxis data", yaxis='y1'), row=1, col=1)
fig.add_trace(go.Scatter(x=[1, 3, 4], y=[40, 50, 10], name="yaxis2 data", yaxis='y2'), row=2, col=1)
fig.add_trace(go.Scatter(x=[1, 5, 6], y=[1000, 2000, 3000], name="yaxis3 data", yaxis='y3'), row=3, col=1)
fig.add_trace(go.Scatter(x=[1, 5, 6], y=[777, 111, 222], name="yaxis4 data", yaxis='y4'), row=4, col=1)

fig.update_layout(
    yaxis=dict(
        title="yaxis title",
    ),
    yaxis2=dict(
        title="yaxis2 title",
        side="left",
        autoshift=True
    ),
    yaxis3=dict(
        title="yaxis3 title", 
        side="left",
        overlaying="y2",
        autoshift=True
    ),
    yaxis4=dict(
        title="yaxis4 title", 
        side="right",
        overlaying="y2"
    ),
)

fig.show()

This produces the following plot, where the two rows only take up half of the figure instead of the full figure, and also only the data for the y4 axis that was (I assume) overlayed last is shown.

For the avoidance of doubt, I am trying to achieve the following:

Thanks so much for any help :slight_smile:
Harry