使用timedelta64作为matplotlib中的X轴

2024-10-01 22:28:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据类型为timedelta64[ns]的numpy数组。但是,将其用作matplotlib绘图中的x轴会显示标签4.320、4.325、4.330等

似乎matplotlib无法正确显示timedelta64,如何将其转换为datetime.timedelta?你知道吗

采样时间:12:00:00.08012

打印arr[2]返回0天12:00:00.08012

x = tbl.time
f, ax = plt.subplots(2, sharex=True)
ax[0].plot(x, tbl.column, label='test', color='red')
ax[1].plot(x, tbl.column2, label='test2', color='blue')
plt.show()

Tags: numpy绘图plotmatplotlibplt标签数组ax

热门问题