在 matplotlib 中编辑 x 轴刻度标签的日期格式

问题描述:

我希望编辑 x 轴上日期的格式.下图显示了默认情况下它们在我的条形图上的显示方式.我想删除重复的 'Dec' 和 '2012',只保留 x 轴上的实际日期数字.

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?

简而言之:

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

matplotlib 网站上的许多示例.我最常用的是这里

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