matplotlib / mplfinance

Financial Markets Data Visualization using Matplotlib
https://pypi.org/project/mplfinance/
Other
3.48k stars 613 forks source link

How can i shade an area between two vertical lines? #630

Closed TraderMan999 closed 1 year ago

TraderMan999 commented 1 year ago

For example, i produce an image that presents each day (one separate image for each day).

On each image i mark a vertical line between 830am est and 1100am est. All that is easily done.

Then i want to shade the area between those two lines. I used the examples provided (https://github.com/matplotlib/mplfinance/blob/master/examples/using_lines.ipynb)

Here's a code snippet:

vls = ['2023-06-02 08:30', '2023-06-02 11:00'] mpf.plot(data, type='candle', vlines = dict(vlines=vls, linewidths=120, alpha=.4))

I shade wtih alpha = .4

The shading is not drawing in the right spot (between 830am and 11am)

Questions: 1) is "linewidths" even relavant or required in my scenario? i played with all kinds of different numbers there but didnt get what i wanted 2) what should i be doing differently to shade only the area between the vertical lines at 830am and 11am?

Here's an example of what im seeing based on the code above:

https://ibb.co/cYQfGyL

As we can see in the image link above, the alpha shading is not between only 830am and 11am

DanielGoldfarb commented 1 year ago

use fill_between in dict mode, specifying y1 and y2 for the vertical boundaries, and use where for the horizontal boundaries (specified as a series of boolean (true/false) values, where the series is the same length as your dataframe). Click here for tutorial.