mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

xticks and fill_between

Open homerjay88xx opened this issue 5 years ago • 2 comments

Hello there,

today I just wanted to thank you for this great package. I'm working with it since a few days and got my first plots done. If you have any feedback on it, how I could improve, I would very much appreciate that.

Things that I'm struggling with so far:

  • Get an xTick on every Monday
  • Get fill_between for subplots

image

homerjay88xx avatar Sep 13 '20 11:09 homerjay88xx

@homerjay88xx , Thanks for expressing your appreciation of mplfinance. Also your plot looks great. Good job. I really enjoy seeing what people are doing with mplfinance.

Regarding your questions: Neither fill_between for subplots, nor modifying xticks, are directly supported (not yet). However there are workarounds for both. Please see this answer here for some more information on how you can use Matplotlib methods to acheive these goals.

In particular I want to mention with regard to xticks that it may be a little tricky. If you set show_nontrading=True it will be easier, because the x-axis will contain actual matplotlib dates, and you can request matplotlib to recognize Mondays for the xticks.

However, when show_nontrading=False (the default value if you specifiy nothing), then internally the x-axis values will be integers representing the row number in your DataFrame. A formatting function maps this row number to the date in the DataFrame Index for display purposes. Therefore, when show_nontrading=False, you will have to take this into account by determining which row numbers of the DataFrame contain Mondays, and specify that you want those row numbers to contain the major x-ticks.

HTH. All the best. --Daniel

DanielGoldfarb avatar Sep 13 '20 20:09 DanielGoldfarb

Currently working on xticks. (fill_between hopefully soon after).

xticks is not trivial for the case of show_nontrading=False, because show_nontrading=False results in an x-axis that is non-linear with respect to time, however I do believe I have an approach that will work for most data sets. Still doing some experiments and hoping to have code for it ready sometime in the next few weeks.

DanielGoldfarb avatar Apr 05 '21 15:04 DanielGoldfarb