mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

ylim kwarg for volume axes

Open ghost355 opened this issue 4 years ago • 4 comments

Hi, how to set ylim for volume panel if I use code like this: mpf.plot(df, volume=ax2) I tried ax2.set_ylim(0,0.5) but it didn't work I think mpf.plot use its own setting

ghost355 avatar Apr 05 '21 09:04 ghost355

Suppose I found something ))) I need add ax2.set_ylim(0,0.5) AFTER mpf.plot()

ghost355 avatar Apr 05 '21 10:04 ghost355

Pavel,

Yes, mpf.plot() has special treatment for volume limits: Since volumes tend to be large numbers, mpf.plot() will make the the lower limit approximately 0.3 times the smallest volume (rather than zero as would otherwise normally be the case).

I thought I had implemented a volume_ylim kwarg, but I guess I only thought about it and didn't actually do it ;-)

There are a couple of workarounds (until volume_ylim is implemented)

  • your suggestion of calling Axes.set_ylim() after calling mpf.plot(). This works for both external axes mode and for returnfig=True mode.
  • use make_addplot() to plot something (even a single data point) on the same axes as the volume, and pass ylim kwarg into make_addplot() (you may also have to pass in secondary_y=False to ensure the ylim gets applied to the correct primary volume axis).

Would you like to implement a volume_ylim kwarg and contribute to mplfinance? I can provide guidance if desired. Thanks. --Daniel

DanielGoldfarb avatar Apr 05 '21 13:04 DanielGoldfarb

Thanks Daniel The way with ax.set_ylim(bottom,top) is very comfortable, I guess and gives very flexible handling. I am afraid, I have no needing skill to contribute any thing to mplfinance )))

ghost355 avatar Apr 05 '21 13:04 ghost355

OK. Thanks. I'm going to leave this issue open as a reminder to me to add a volume_ylim kwarg.

DanielGoldfarb avatar Apr 05 '21 14:04 DanielGoldfarb