2021年2月10日星期三

When using external axes method to plot multiple candlestick charts using mplfinance library, how to plot volume inside the candlestick chart?

The project I am doing requires code to plot more than 300 candlestick charts in several figures using mplfinance library. I am aware that this can only be done using external axes method as it provides more flexibilities and can plot unlimited charts theoretically.

The current code I am using is as below, the charts plotted can be seen below:

import mplfinance as mpf    s = mpf.make_mpf_style(base_mpf_style='yahoo', rc={'font.size': 6})  fig = mpf.figure(figsize=(34, 13.2), style=s, tight_layout=True)    ax_p = fig.add_subplot(n_rows, n_cols, pos_price)  ax_v = fig.add_subplot(n_rows, n_cols, pos_vol, sharex=ax_p)    fig, ax_list = mpf.plot(resampled_df, type='candle', ax=ax_p, volume=ax_v, show_nontrading=False,                       datetime_format='%a %d-%m-%y', xrotation=0, returnfig=True)  

The screenshot of the 6 sample charts from hundreds of charts my code plotted:

enter image description here

The screenshot of the two charts the above code plotted is as below: enter image description here

As you can see the volume chart was plotted in an individual chart below the candlestick chart. I struggle to find the solution to move the volume into candlestick chart, there is a similar post in mplfinance documentation issue 114 kind of explains how to do this...... but I found it is rather difficult to understand for new ppl to the library like me.

Would highly appreciate it if you could post the detailed code to do this!

https://stackoverflow.com/questions/66147746/when-using-external-axes-method-to-plot-multiple-candlestick-charts-using-mplfin February 11, 2021 at 09:58AM

没有评论:

发表评论