pyplot не имеет атрибута 'xaxis_set_major_formatter' - PullRequest
0 голосов
/ 02 марта 2020

Я пытаюсь нанести часы по оси 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: module 'matplotlib. У pyplot 'нет атрибута' xaxis_set_major_formatter '

У меня есть индекс в качестве индекса. Как мне решить эту проблему?

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 [нс] ', длина = 193, freq =' H ')

1 Ответ

0 голосов
/ 02 марта 2020

Это должно быть xaxis.set_major_formatter

Также xaxis является свойством ax. Так что вы могли бы сделать

ax.xaxis_set_major_formatter(monthyearFmt)
...