Algin multiple y-achse on Plotly

hi Everyone
i have a small problem and that i canot algin both Y-achse together, there is allways a offset between them.
can somebody check my Code and help me with it
thanks alot

    'layout': dict(title={'text': 'Balken'},
                   yaxis={'title': {'text': y_axis_text},
                          'rangemode': 'tozero', 
                          'yaxis2': False, 'showgrid': True},
                   xaxis={'title': {'text': 'Amount of measurements'}, 'dtick': 5},

                   yaxis2={'title': 'Bits', 'overlaying': 'y', 'side': 'right', 'rangemode': 'tozero',
                           'scaleanchor': 'yaxis', 'constraintoward': 'bottom', 'yaxis2': True,
                         'showgrid': True
                           })})

Hi @hamoudie12

You can do it using the following steps:

You can do it like this:

  1. Set (or find) appropriate minimum and maximum values for your y-axis,

  2. adjust your y ranges using fig.update_layout(yaxis=dict(range=[all_min,all_max]), yaxis2=dict(range=[all_min,all_max])) , and

  3. set the scaleanchor of your secondary y-axis to y1 like this: fig.update_layout(yaxis2=dict(scaleanchor = 'y1'))

If the source of your figure data is a pandas DataFrame, there are more elegant ways of finding global max and min values than just hard-coding them in there.

Check out other methods here:

2 Likes