答案 0 :(得分:0)
您应该能够将其他图指定为水平条形图,它们将出现在创建的第一个图的顶部。这是我在水平图上绘制水平条形图的方法。用于此目的的数据组成了该图,虽然它不是很漂亮,但是代码将是相同的。
N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)
womenStd = (3, 5, 2, 3, 3)
ind = np.arange(N) # the x locations for the groups
y_pos = [10, 20, 30, 40, 50] #locations of the horizontal bars
width = 0.35 # the width of the bars
h_width = 1.0 #width of the horizontal bars
h_x_loc = 1.18 #This will be used to change the x location of the
#horizontal bars.
p1 = plt.bar(ind, menMeans, width, yerr=menStd)
p2 = plt.barh(y_pos, womenStd, width, left=h_x_loc, yerr=0)
plt.ylabel('Scores')
plt.title('Scores by group and gender')
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
plt.yticks(np.arange(0, 81, 10))
plt.legend((p1[0], p2[0]), ('Men', 'Women'))
plt.show()
请注意,要使每组水平条与正确的相应垂直条对齐,您将需要为每组绘制一个单独的图并更改该组的x位置。