我有一个超过一年的数据点的直方图。一切正常,除了月份显示为数字。我想用他们的名字显示它们。而不是“01”,它应该说“一月”(也稍微旋转,但我自己可以这样做。)我如何告诉 maplotlib 使用月份名称?我已经查看了文档和其他帖子,但无法使其工作。我的代码:fig = plt.figure(figsize=(12,6))s = fig.add_subplot(111)s.hist(mydata,bins=120,stacked=True, color=mycolors, alpha=1)s.xaxis.set_major_locator(mdates.MonthLocator())s.xaxis.set_major_formatter(mdates.DateFormatter('%m'))s.legend(legend)作为mydata形状 (n,1) 的数据帧列表。我是 matplotlib 的新手,不完全理解发生了什么,s.xaxis.set_major_formatter(mdates.DateFormatter('%m'))但我猜这条线需要修改吗?我的代码结果如下图:
2 回答

当年话下
TA贡献1890条经验 获得超9个赞
只需要替换 mdates.DateFormatter 中的月份格式:
#fig = plt.figure(figsize=(12,6))
#s = fig.add_subplot(111)
#s.hist(mydata,bins=120,stacked=True, color=mycolors, alpha=1)
#s.xaxis.set_major_locator(mdates.MonthLocator())
s.xaxis.set_major_formatter(mdates.DateFormatter('%b'))
OR
s.xaxis.set_major_formatter(mdates.DateFormatter('%B'))
#s.legend(legend)
B = 长名称 b = 缩写名称
添加回答
举报
0/150
提交
取消