如果我正确理解你,你想要一个叠加多于两个元素的堆栈图?如果是的话,那就像在你发布的例子中那样直截了当:
#!/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()
你的问题是什么? – tacaswell
这是最后一行:现在如何绘制[M,F +其他],抱歉缺少问号。 – hylepo
我并不真正站在你想要做的事情上。你可以发布(在问题中,而不是在链接中)代码,尽可能接近你想要的吗? – tacaswell