在 matplotlib 中编辑 x 轴刻度标签的日期格式 [英] Editing the date formatting of x-axis tick labels in matplotlib

查看:44
本文介绍了在 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

这篇关于在 matplotlib 中编辑 x 轴刻度标签的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆