Is there a way to plot the volume and OHLC data on the same panel?
I tried putting the panel IDs same for both but that only plots the volume data (I guess the volume data is plotted onto later, and hence replaces the OHLC data?).
kwargs = {
'type': "candle",
'volume': True,
'volume_panel': 0,
'main_panel': 0,
'mav': (6,9),
'title': f"{self.meta['2. Symbol']}",
'show_nontrading': True,
'style': self.plotStyle,
'addplot': adps
}
mplf.plot(self.ohlcv, **kwargs)
Mplfinance actually is plotting both OHLC and Volume.
The problem is that the prices and volume are being plotted on the same y-axis and, most likely, your volume values are several or many orders of magnitude greater than the prices. Thus you don't see the prices.
The workaround for this is to plot either volume, or ohlc, separately using mpf.make_addplot()
(use type='bar'
for volume, and type='ohlc'
or type='candle'
for ohlc data). In the call to mpf.make_addplot()
you then may need to set secondary_y=True
(or it may work automatically).
Alternatively, your question gave me the idea to enhance mplfinance to automatically put the volume on the secondary axes if it detects that the ohlc and volume data are on the same panel. Thus you can avoid the need to call make_addplot()
in order to place one of them on the secondary axes.
This enhancement is in mplfinance version v0.12.9b1, so you will need to install that version. With this enhancement, all you have to do is what you tried above, that is, simply set volume_panel
and main_panel
to the same value and everything should work automatically.
With this enhancement, there are two addition kwargs to mpf.plot()
that you may find useful:
volume_alpha=
to set the opacity of the volume bars (in case you want them to be lighter or more transparent, allowing the ohlc data to be more apparent and/or stand out.volume_ylim=
to be able to set the y-axis minumum and maximum for the volume, in case you want the volume bars to be somewhat smaller in appearance (by setting the volume_ylim
maximum to a value significantly larger than the maximum volume).