How to edit the fig with the new mplfinance package?

╄→гoц情女王★ 提交于 2021-01-28 11:58:50

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/61547880/how-to-edit-the-fig-with-the-new-mplfinance-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!