Python pyplot没有属性';xaxis#u set_major#u格式化程序';

Python pyplot没有属性';xaxis#u set_major#u格式化程序';,python,datetime,xticks,Python,Datetime,Xticks,我试图用这个代码在x轴上画出小时数 #create a lineplot fig = plt.figure(figsize=(20,5)) ax = fig.add_subplot() plt.title('SUBIC-NAIA Air Temp Difference. (C)') ax.plot(date_rng,NASU_dif) monthyearFmt = mdates.DateFormatter('%Y-%m-%d-%h') plt.xaxis_set_major_formatter(

我试图用这个代码在x轴上画出小时数

#create a lineplot
fig = plt.figure(figsize=(20,5))
ax = fig.add_subplot()
plt.title('SUBIC-NAIA Air Temp Difference. (C)')
ax.plot(date_rng,NASU_dif)
monthyearFmt = mdates.DateFormatter('%Y-%m-%d-%h')
plt.xaxis_set_major_formatter(monthyearFmt)
plt.xlabel('Time Step (hr)')
plt.ylabel('Air Temperature (m/s)')
plt.legend(loc='upper right', prop={'size': 10})
plt.show()
但是我收到了

AttributeError:模块“matplotlib.pyplot”没有属性 “xaxis\u集合\u主要\u格式化程序”

我有一个日期作为索引。我如何解决这个问题

DatetimeIndex(['2018-04-22 00:00:00','2018-04-22 01:00:00', '2018-04-22 02:00:00', '2018-04-22 03:00:00', '2018-04-22 04:00:00', '2018-04-22 05:00:00', '2018-04-22 06:00:00', '2018-04-22 07:00:00', '2018-04-22 08:00:00', '2018-04-22 09:00:00', ... '2018-04-29 15:00:00', '2018-04-29 16:00:00', '2018-04-29 17:00:00', '2018-04-29 18:00:00', '2018-04-29 19:00:00', '2018-04-29 20:00:00', '2018-04-29 21:00:00', '2018-04-29 22:00:00', '2018-04-29 23:00:00', '2018-04-30 00:00:00'], dtype='datetime64[ns]',length=193,freq='H')


它应该是
xaxis.set\u main格式化程序

另外,
xaxis
ax
的属性。所以你可以

ax.xaxis_set_major_formatter(monthyearFmt)

嗨,谢谢你的回复。我没有注意到“u”部分。尽管,即使在使用了xaxis.set_major_格式化程序之后,我仍然发现模块“matplotlib.pyplot”没有属性“xaxis”,这是否回答了您的问题?