绘制 datetime.time python / matplotlib 的直方图

问题描述 投票:0回答:2

我正在尝试绘制 datetime.time 值的直方图。这些值被离散化为五分钟的切片。数据看起来像这样,在列表中:

['17:15:00', '18:20:00', '17:15:00', '13:10:00', '17:45:00', '18:20:00']

我想绘制一个直方图,或者某种形式的分布图,以便可以轻松检查每次出现的次数。

注意。然后将给定的每个时间离散化。直方图中的最大箱数为

288 = (60 / 5 * 24)

我看过

matplotlib.pyplot.hist
。但需要某种连续标量

python datetime matplotlib histogram
2个回答
10
投票

我按照 David Zwicker 的说法使用了秒,然后更改了 x 轴。我会看看戴夫所说的“垃圾箱”。这大致有效,并给出了每小时的柱图。

def chart(occurence_list):
    hour_list = [t.hour for t in occurence_list]
    print hour_list
    numbers=[x for x in range(0,24)]
    labels=map(lambda x: str(x), numbers)
    plt.xticks(numbers, labels)
    plt.xlim(0,24)
    plt.hist(hour_list)
    plt.show()

frequency of lowest daily exchange rate for GBPUSD


-10
投票

您必须将数据转换为两个变量,然后您可以使用plotlab绘制直方图。

© www.soinside.com 2019 - 2024. All rights reserved.