Search code examples
pythonmatplotlibxticks

Editing the date formatting of x-axis tick labels


I am looking to edit the formatting of the dates on the x-axis. The picture below shows how they appear on my bar graph by default. I would like to remove the repetition of 'Dec' and '2012' and just have the actual date numbers along the x-axis.

Any suggestions as to how I can do this?

enter image description here


Solution

  • In short:

    import matplotlib.dates as mdates
    myFmt = mdates.DateFormatter('%d')
    ax.xaxis.set_major_formatter(myFmt)
    

    Many examples on the matplotlib website. The one I most commonly use is here