我正在尝试使用堆积的条形图绘制两个子图,一个在另一个下。我可以生成堆叠的条形图和子图,但是无法将两者结合在一起,一个在另一个下面。有人知道我可以看的一些不使用熊猫的代码吗?我一直无法安装pandas,只能安装numpy和matplotlib。
谢谢。
答案 0 :(得分:0)
import numpy as np
import matplotlib.pyplot as plt
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
width = 0.35 # the width of the bars: can also be len(x) sequence
fig,axes = plt.subplots(nrows = 2)
fig.subplots_adjust(hspace=0.5, wspace=0.3)
for i,ax in enumerate(axes.flat):
ax.bar(ind, menMeans, width, yerr=menStd)
ax.bar(ind, womenMeans, width,
bottom=menMeans, yerr=womenStd)
ax.set_title('Scores by group and gender')
ax.set_xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
ax.set_yticks(np.arange(0, 81, 10))
ax.legend((p1[0], p2[0]), ('Men', 'Women'))
plt.show()
输出: