时间类型错误直方图

TypeError histogram of time

我正在尝试按小时绘制时间

    time_new=[x[:2]+":"+x[2:] for x in time_cleaned]        
    hour_list = [t[:2] for t in time_new]
    print hour_list
    numbers=[x for x in xrange(0,24)]
    labels=map(lambda x: str(x), numbers)
    plt.xticks(numbers, labels)
    plt.xlim(0,24)
    pdb.set_trace()
    plt.hist(hour_list)
    plt.show()

我在第 plt.hist(hour_list)

行收到此错误 TypeError: 'len() of unsized object'
pprint(time_new)
['09:00',
 '23:30',
 '19:05',
 '09:00',
 '01:00',
 '02:00',
 '19:00',
 '05:30',
 '04:00',
 '20:00',
 '23:30',
 '10:30',
 '20:00',
 '05:0',
 '21:30',
 '17:30',
 '04:55',
 '13:45',
 '08:40',
 '13:00',
 '06:00',
 '19:45',
 '09:00',
 '14:30',
 '09:00',
 '10:30',
 '23:07',
 '19:00',
 '23:40',
 '20:30',
 '19:30',
 '06:00',
 '05:30',
 '24:00',
 '20:30',
 '19:00',
 '15:05',
 '14:15',
 '19:20',
 '14:00',
 '15:15',
 '21:00']
(Pdb) 

编辑: 通过以下方式修复:

hour_list = [int(t[:2]) for t in time_new]

我的历史是错误的。

编辑 2:

您似乎在尝试将字符串绘制为值。尝试将 hour_list 更改为:

hour_list = [int(t[:2]) for t in time_new]