mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

Support `fill_between` in "External Axes" Mode. And Support multiple `fill_between`s

Open qililiu opened this issue 4 years ago • 2 comments

Describe the bug in "External Axes Method", the 'fill_between' function does not work.

To Reproduce `import mplfinance as mpf idf = pd.read_csv('data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True)

fig = mpf.figure(style='yahoo',figsize=(7,8))

ax1 = fig.add_subplot(2,1,1)

ax2 = fig.add_subplot(2,1,2)

mpf.plot(idf,ax=ax1,volume=ax2,fill_between=130) `

Expected behavior An candlestick plot with shaded region at prices 0-130.

Screenshots Figure 2020-11-11 222511

Desktop (please complete the following information):

  • OS: Windows 10, python 3.8, Spyder

qililiu avatar Nov 12 '20 03:11 qililiu

This is not a bug, but by design, when in "external axes mode," the fill_between kwarg gets ignored. There are several kwargs that get ignored when in "external axes mode", most of which display a warning if the user sets that kwarg and external axes mode at the same time. This one probably should also display a warning.

That said, I am having doubts about whether or not to keep this design. My original thinking was that since, in external axes mode, the user already has full control over the axes, then the user can call Axes.fill_between() themselves. (That can also serve as a possible work-around for the fact that presently only one fill_between is supported, see #218). However calling Axes.fill_between(), directly, presents certain problems for the caller, in regards to the x-axis, as described in this comment.

The more I think about it, the more I think that the caller should not have to worry about those x-axis issues. Rather mplfinance should handle that internally. Therefore, in addition to adding support for multiple fill_between's, I think we should also enhance the code to support fill_betweens even in external axis mode. The only issue with doing that is we will have to come up with a way to make it clear to which Axes object each fill_between specification should be applied.

I hope that makes sense. Please let me know if you have any other questions.

All the best. --Daniel

DanielGoldfarb avatar Nov 13 '20 18:11 DanielGoldfarb

Thank you Daniel for your comment. Looking forward to the future updates on these features.

qililiu avatar Nov 15 '20 01:11 qililiu