2013-05-31 127 views
-1

matplotlib陰謀酒吧matplotlib先進的堆疊酒吧

它可以是常規的像http://matplotlib.org/examples/api/barchart_demo.html

讓我們將此定義爲[M,F]

可以堆疊像http://matplotlib.org/examples/pylab_examples/bar_stacked.html

讓我們定義這作爲[M + F]

現在如何繪製[M,F +其他]

+0

你的問題是什麼? – tacaswell

+0

這是最後一行:現在如何繪製[M,F +其他],抱歉缺少問號。 – hylepo

+0

我並不真正站在你想要做的事情上。你可以發佈(在問題中,而不是在鏈接中)代碼,儘可能接近你想要的嗎? – tacaswell

回答

1

如果我正確理解你,你想要一個疊加多於兩個元素的堆棧圖?如果是的話,那就像在你發佈的例子中那樣直截了當:

#!/usr/bin/env python 
# a stacked bar plot with errorbars 
import numpy as np 
import matplotlib.pyplot as plt 


N = 5 
menMeans = [20, 35, 30, 35, 27] 
womenMeans = [25, 32, 34, 20, 25] 
otherMeans = [5, 2, 4, 8, 5] 
menStd  = [2, 3, 4, 1, 2] 
womenStd = [3, 5, 2, 3, 3] 
otherStd = [1, 1, 1, 1, 1] 
ind = np.arange(N) # the x locations for the groups 
width = 0.35  # the width of the bars: can also be len(x) sequence 

p1 = plt.bar(ind, menMeans, width, color='r', yerr=womenStd) 
p2 = plt.bar(ind, womenMeans, width, color='y', 
      bottom=menMeans, yerr=menStd) 
p3 = plt.bar(ind, otherMeans, width, color='b', 
      bottom=[menMeans[j] + womenMeans[j] for j in range(len(menMeans)) ], 
      yerr=otherStd) 

plt.ylabel('Scores') 
plt.title('Scores by group and gender') 
plt.xticks(ind+width/2., ('G1', 'G2', 'G3', 'G4', 'G5')) 
plt.yticks(np.arange(0,81,10)) 
plt.legend((p1[0], p2[0], p3[0]), ('Men', 'Women', 'Other')) 

plt.show() 
+0

好的,謝謝,我意識到 – hylepo