python - Matplotlib xaxis.set_major_formatter 不理解年份
问题描述
信息
我有以下绘制的 pd.dataframe
ax = dfPivot.plot()
plt.grid()
plt.grid(which='minor')
plt.show()
In [4]: dfPivot.index
Out[4]:
DatetimeIndex(['2020-05-26 12:00:33', '2020-05-26 12:02:13',
'2020-05-26 12:03:53', '2020-05-26 12:05:33',
'2020-05-26 12:07:13', '2020-05-26 12:08:53',
'2020-05-26 12:10:33', '2020-05-26 12:12:13',
'2020-05-26 12:13:53', '2020-05-26 12:15:33',
...
'2020-05-29 09:08:53', '2020-05-29 09:10:33',
'2020-05-29 09:12:13', '2020-05-29 09:13:53',
'2020-05-29 09:15:33', '2020-05-29 09:17:13',
'2020-05-29 09:18:53', '2020-05-29 09:20:33',
'2020-05-29 09:22:13', '2020-05-29 09:23:53'],
dtype='datetime64[ns]', name='DateTime', length=2499, freq=None)
它工作正常。
问题
当我使用以下格式格式化 X 轴时遇到问题:
myFmt = mdates.DateFormatter("%d/%m/%y %H:%M:%S") # tried with "%x %X" or any other combination, failed.
ax.xaxis.set_major_formatter(myFmt)
蟒蛇掉了一个:
rom_ordinalf
dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC) ValueError: year 4354626 is out of range
当我使用 set_major_formatter() 时,我不明白哪个被处理不同。我认为这只是美学上的改变,但似乎更深入。
我认为 matplotlib 正在“尝试”在我的 pd.datetime64[ns] 上查找和美国类型日期并且失败但不知道如何继续。
谢谢
解决方案
推荐阅读
- protocol-buffers - 使用protobuf注释时如何删除未使用的类型化需求
- android - 如何在通知的单击上显示对话框
- azure - 是否可以为 Azure 指标生成自定义电子邮件报告?
- powershell - 在 PowerShell 中更改语言可抑制错误
- javascript - 如何将下拉列表中的值设置为框中的默认值?
- java - 如何使用 Frida 获取 ANDROID_ID
- reporting-services - 如何在 SSRS 中获取月份和年份的“mmm-YYYY”格式的日期
- arrays - 如何从Angular 5应用程序中来自json的数组中获取值?
- xamarin.forms - 使用 Firebase 使用 xamarin 表单进行用户存在跟踪
- javascript - 我想更改页面内容而不重新加载角度 6