How to match subplot ranges in mplfinance

Viewed 25

When drawing the RSI, I am thinking of drawing the 25% and 75% horizontal lines. With automatic range adjustment, the 25% line is displayed as a separate axis on the right side from 20 to 30. I can use ylim=() to adjust the range and it works fine, but it still doesn't combine the 75% on the left side with the RSI axis, and the scale is displayed on the right side, which is not smart. Is there a better way to do this?

Translated with www.DeepL.com/Translator (free version)

1 Answers

Are you using hlines or mpf.make_addplot() to draw your 25% and 75% lines? It sounds like you are using mpf.make_addplot() (otherwise the hlines would be drawn on the same axis as the prices).

If so, when calling mpf.make_addplot() use kwarg secondary_y.

As explained between cells In [15] and In [16] in the addplot tutorial ...

  • mpf.make_addplot() has a keyword argument called secondary_y which can have three possible values: True, False, and 'auto'.
    • The default value is 'auto' which means if you don't specify secondary_y, or if you specify secondary_y='auto', then mpf.plot() will attempt to decide whether a secondary y-axis is needed, by comparing the order of magnitude of the addplot data with the order of magnitude of the data that is already on the plot.
    • If mpf.plot() gets it wrong, you can always override by setting secondary_y=True or secondary_y=False.
Related