python-3.xmplfinance

how to make the mplfinance charts always display years


the mplfinance chart will only display years when the dates of the data are crossing different years (here 2014-2015) like:

enter image description here

otherwise, the dates on the chart will look like:

enter image description here

how to make the year information always be displayed on the chart?


Solution

  • Use kwarg datetime_format= when calling mpf.plot(). So, for example, to get the format that you described above, do:

    mpf.plot(df,...,datetime_format="%Y-%b-%d")
    

    See all of the available format codes here: https://strftime.org/