一月份的小勾号标签未显示在matplotlib中

问题描述 投票:0回答:1

我正在绘制时间序列的数据,并具有年份的主要刻度线和月份的次要刻度。一切看起来都不错,除了一年中未出现一月份的“ 01”。有人对如何解决此问题有任何建议吗?谢谢!

代码和相关的图形输出在下面。


fig=plt.figure(figsize=(40,30))
ax1 = plt.subplot(411)
plt.title('Moving Window Plot: Downsview 2015-2020',size=30)
ax2 = plt.subplot(412)
ax3 = plt.subplot(413)


ax1.errorbar(ym_grp.index,ym_grp.slope, yerr=ym_grp_sem.slope, ls='none',marker = 'o')
ax2.errorbar(ym_grp.index,ym_grp.yint, yerr = ym_grp_sem.yint, ls='none',marker = 'o')
ax3.errorbar(ym_grp.index,ym_grp.r2, yerr =ym_grp_sem.r2, ls='none', marker = 'o')

ax1.xaxis.set_major_locator(matplotlib.dates.YearLocator())
ax1.xaxis.set_minor_locator(matplotlib.dates.MonthLocator())

ax1.xaxis.set_major_formatter(matplotlib.dates.DateFormatter("\n%Y"))
ax1.xaxis.set_minor_formatter(matplotlib.dates.DateFormatter("%m"))
plt.setp(ax1.get_xticklabels(), rotation=0, ha="center")

ax3.set_xlabel('Time (UTC)',fontsize=20)
ax1.set_xlim()

ax1.set_ylabel('ΔCO/ΔCO₂',fontsize=20)
ax2.set_ylabel('offset',fontsize=20)
ax3.set_ylabel('r-squared',fontsize=20)

输出:

graph output

python matplotlib
1个回答
0
投票

将月份添加到主要刻度格式中:

ax1.xaxis.set_major_formatter(matplotlib.dates.DateFormatter("%m\n%Y"))
© www.soinside.com 2019 - 2024. All rights reserved.