以AM/PM格式绘制Pandas日期时间序列

2024-10-04 07:39:27 发布

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

我有一个熊猫系列的时间戳索引,我想绘制。在

print example.head()

2015-08-11 20:07:00-05:00    26
2015-08-11 20:08:00-05:00    66
2015-08-11 20:09:00-05:00    71
2015-08-11 20:10:00-05:00    63
2015-08-11 20:11:00-05:00    73

但当我在《熊猫》中用:

^{pr2}$

我希望y轴上的值以AM/PM格式显示(8:08PM),而不是军事时间(20:08)。有没有一个简单的方法可以做到这一点?在

还有,我该如何控制蜱虫的数量和与大熊猫密谋的标签?在

提前谢谢。在


Tags: 方法数量example格式时间绘制标签am
1条回答
网友
1楼 · 发布于 2024-10-04 07:39:27

你的问题有两个要素:

  1. 如何控制绘图上的刻度/标签
  2. 如何将24小时制改为12小时制

axis方法set_xticksset_yticksset_xticklabels和{}控制记号和标签:

import matplotlib.pyplot as plt

plt.plot(range(10), range(10))
plt.gca().set_xticks(range(0,10,2))
plt.gca().set_xticklabels(['a{}'.format(ii) for ii in range(0,10,2)])

要更改时间格式,请使用pd.datetime.strftime公司:How can I convert 24 hour time to 12 hour time?

^{pr2}$

这个问题涵盖了另一种绘制日期的方法:Pandas timeseries plot setting x-axis major and minor ticks and labels

相关问题 更多 >