2013-09-27 238 views
2

我想要舉例說明如何繪製集羣水平條形圖中每個日期的平均值,最大值,最小值的值。y軸日期的水平條形圖

dates = [datetime.datetime(2011, 1, 2, 0, 0, 25, 135000), 
datetime.datetime(2011, 2, 2, 0, 0, 57, 386000), 
datetime.datetime(2011, 3, 2, 0, 0, 59, 579000), 
datetime.datetime(2011, 4, 2, 0, 0, 27, 676000), 
datetime.datetime(2011, 5, 2, 0, 0, 25, 135000), 
datetime.datetime(2011, 6, 2, 0, 0, 26, 414000), 
datetime.datetime(2011, 7, 2, 0, 0, 28, 145000), 
datetime.datetime(2011, 8, 2, 0, 0, 26, 432000), 
datetime.datetime(2011, 9, 2, 0, 0, 27, 301000), 
datetime.datetime(2011, 10, 2, 0, 0, 27, 643000), 
datetime.datetime(2011, 11, 2, 0, 0, 27, 673000), 
datetime.datetime(2011, 12, 2, 0, 0, 28, 294000)] 


mean = [-10.246537396121893, 1.3039215686274515, 1.007462686567164, 
-0.12771084337349403, -0.1932367149758454, -0.3196125907990315, 
-0.04128440366972498, -0.19950738916256117, -1.6319018404907975, 
-1.1532258064516134, -1.666666666666668, -2.3958333333333326] 


max = [-8.0, 19.0, 11.0, 6.0, 6.0, 6.0, 6.0, 6.0, 2.0, 2.0, 2.0, 2.0] 


min = [-12.0, -7.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -7.0, -7.0] 

我試圖與BARH方法沒有成功爲具有d顯示y軸側。

dates = [datetime.datetime(2011, 1, 2, 0, 0, 25, 135000), 
    datetime.datetime(2011, 2, 2, 0, 0, 57, 386000), 
    datetime.datetime(2011, 3, 2, 0, 0, 59, 579000), 
    datetime.datetime(2011, 4, 2, 0, 0, 27, 676000), 
    datetime.datetime(2011, 5, 2, 0, 0, 25, 135000), 
    datetime.datetime(2011, 6, 2, 0, 0, 26, 414000), 
    datetime.datetime(2011, 7, 2, 0, 0, 28, 145000), 
    datetime.datetime(2011, 8, 2, 0, 0, 26, 432000), 
    datetime.datetime(2011, 9, 2, 0, 0, 27, 301000), 
    datetime.datetime(2011, 10, 2, 0, 0, 27, 643000), 
    datetime.datetime(2011, 11, 2, 0, 0, 27, 673000), 
    datetime.datetime(2011, 12, 2, 0, 0, 28, 294000)] 

data_values = [ 
[-10.246537396121893, 1.3039215686274515, 1.007462686567164, 
-0.12771084337349403, -0.1932367149758454, -0.3196125907990315, 
-0.04128440366972498, -0.19950738916256117, -1.6319018404907975, 
-1.1532258064516134, -1.666666666666668, -2.3958333333333326], #mean 
[-8.0, 19.0, 11.0, 6.0, 6.0, 6.0, 6.0, 6.0, 2.0, 2.0, 2.0, 2.0], #max 
[-12.0, -7.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -7.0, -7.0]]#min 

width = 0.35 
ind = arange(len(dates)) 

for i in range(len(data_values)): 
    plt.barh(ind + width * i, data_values[i], width) 

如何顯示對應於日期的每個平均值,最大值,最小值的y軸側的日期?感謝幫助。

+1

懷疑你可能真的想要一個箱線圖這裏http://matplotlib.org/api/axes_api。 HTML#matplotlib.axes.Axes.boxplot – tacaswell

回答

4

這是你要找的效果嗎?

horizontal bar

的關鍵是使用matplotlib.dates模塊以正確的格式日期:

fig = plt.figure() 
ax = fig.add_subplot(1,1,1) 
datenum = matplotlib.dates.date2num(dates) 

for i in range(-1,len(data_values)-1): 
    ax.barh(datenum + i*5., data_values[i], height=5.) 
ax.yaxis.set_major_formatter(matplotlib.dates.DateFormatter('%m/%d')) 

plt.show()