edd
edd

Reputation: 291

How to edit the fig with the new mplfinance package

I can't seem to add any text, rotate axis, change the background color, etc with the new mplfinance.

With the old mpl-finance, I just do fig, ax = plt.subplots() and edit the fig and ax however I want to like: fig.text(0.96, 1, 'some text', size=9, fontweight='bold',color='black', ha="right") or plt.legend( loc='upper left')

Does anyone know how to do that with the new package?

Upvotes: 2

Views: 3216

Answers (1)

Daniel Goldfarb
Daniel Goldfarb

Reputation: 7714

To gain access to mplfinance's Figure and Axes objects, there are two ways:


Method 1. Set returnfig=True when calling plot:

  fig, axlist = mpf.plot(data,...,returnfig=True,...)  

axlist will be a list of axes corresponding to the panels from top to bottom, two axes per panel where the first is the primary axes and the next is the _secondary axes. For example, if you have 3 panels then returnfig=True will return 6 Axes objects. axlist[0] and axlist[1] will be the primary and secondary axes, respectively, for panel 0. axlist[2] and axlist[3] will be the primary and secondary axes, respectively, for panel 1, etc.


Method 2. Create your own Figure and Axes objects and pass these into mplfinance. You can see examples of how to do this here.


Please note also that, when specifying x,y coordinates for positioning of text, legends, etc. then:

if show_nontrading kwarg is False (i.e. the default value if unspecified) then the x-axis values are not actually dates as they appear, but are integer values from zero up to the number of rows in your dataframe.

HTH

Upvotes: 4

Related Questions