【发布时间】:2021-03-22 16:39:16
【问题描述】:
我有这个 pandas 数据框,我想通过只显示天、小时、分钟和秒来绘制它。
随着时间的推移,我有一个以毫秒为单位的 Unix 时间戳,我将其转换为您在数据框中已经看到的格式。
frm = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
df['startTime'] = pd.to_datetime((df['startTime']), unit='ms')
print(df)
plt.plot_date(df['startTime'], df['parameter.value'], linestyle='solid')
plt.gcf().autofmt_xdate()
plt.gca().xaxis.set_major_formatter(frm)
plt.show()
虽然我使用 DateFormatter 对其进行了格式化,但分钟和秒仍然没有出现在图中。
【问题讨论】:
-
您能提供一个minimal reproducible example吗?这只是为了让任何回答的人都可以重现问题并能够更有效地诊断它。最好有一个示例,包括您的数据框是如何创建和格式化的。
标签: python pandas matplotlib pycharm dateformatter