Search code examples
pythonplotlyvisualization

Python Plotly y-axis ranges do not match for subplots and won't allow me to manually define them


Two Plotly Scatter Plots combined in one subplot

In my Plotly subplots, the top graph has a range of [0,10], while the bottom has a range of [0,14]. Other questions regarding this on SO (Plotly: How to change the range of the y-axis of a subplot?) have suggested using the following:

fig.update_layout(yaxis = dict(range=[0, 14]))
fig.update_layout(yaxis2 = dict(range=[0, 14]))

This has not fixed the issue. It does not cause any errors, but neither does it fix my problem. I need them to have the same range in order to properly show the scale of the differences between the two.

I have tried manually adjusting the ticks but I have been unable to find a value that allows be to define the number of ticks or to manually add ticks to the y-axis.

Any help is appreciated, thank you.


Solution

  • If you want all your y-axes to have the same range, try this:

    fig = make_subplots(rows=2, cols=1, shared_yaxes='all')
    

    https://plotly.com/python-api-reference/generated/plotly.subplots.make_subplots.html