matplotlib / mplfinance

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

Interactive plots for OHLC candles with mplfinance #667

Closed ETTAN93 closed 2 months ago

ETTAN93 commented 3 months ago

Hi, is it possible to generate an interactive plot for Open, High, Low, Close candles plot with mpf.plot()?

I am looking to do mainly 2 things: i. Zoom in to particular sections of the plots ii. Hovering over the lines should provide the details of a particular point

An example of my static graph currently looks something like this: image

DanielGoldfarb commented 3 months ago

Interactivity depends on the "matplotlib backend" you use. Although it is called "backend" (from the point of view of matplotlib code) the term refers the the portion of code that renders on screen and relates to the user interface. Matplotlib (and by extension mplfinance) is designed to work with a number of different backends. Since interactivity is a property of the backend, it not trivial to code within mplfinance itself (since the code would have to behave differently depending on which backend the user is using).

If you use the standard matplotlib interface (that is run your mplfinance program as a python script not within jupyter notebook) you will automatically get zooming and panning. Hovering also gives details of points but will not necessarily give OHLC, and if show_nontrading=False (the default value) the the hover will show the row number in the dataframe as opposed to the date. Cross hairs can be coded as discussed here.

At some point I hope to code up an example (or someone else can volunteer to do it) showing how to implement a hover that displays OHLCV data for each candle, but (for reasons mentioned above) we do not plan to build such code into mplfinance.

For more information see also: https://matplotlib.org/stable/users/explain/figure/interactive.html