仅在Matplotlib中打印时间(而不是DateTime)

2024-09-26 22:50:51 发布

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

我的数据帧是这种格式

   Time    AvgDiff
07:00:00   7.750782
07:01:00   9.306567
07:02:00  13.225209
07:03:00  18.346431
07:04:00  10.049761
07:05:00  18.567049
07:06:00  -4.903014
07:07:00 -10.66217

我做了以下事情来创建一个合成日期,日期并不重要,因为我的AvgDiff是特定时间值的所有日期的平均值

^{pr2}$

这表明

enter image description here

它同时显示日期和时间(在X轴上),但是我需要它只显示小时和分钟。在

我试过了

FMT = '%H:%M:%S'
df['Time'] = df['Time'].map(lambda x: datetime.strptime(str(x), FMT))
df['Time'] = df['Time'].map(lambda x: x.replace(day=date, month=month, year=year))
plt.gcf().autofmt_xdate()
plt.show()

但它产生了完全相同的图表,为什么会这样呢?在


Tags: 数据lambdamapdftime格式时间plt

热门问题