0
我有一個數組,其時間戳爲ts_array
,格式爲dd-mm-yyyy
,如03-08-2012
。現在我想用matplotlib 1.5.1
繪製直方圖和Python 2.7
如下:使用Python生成直方圖
import matplotlib.pyplot as plt
timestamps = dict((x, ts_array.count(x)) for x in ts_array)
plt.hist(timestamps)
plt.title("Timestamp Histogram")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
例如在哪裏timestamps = {'03-08-2012': 108, '15-08-2012': 16}
。
當我嘗試運行它時,它會拋出TypeError: len() of unsized object
。我如何繪製一個直方圖,其中x軸上的日期(鍵)和y軸上的計數(值)?