我正在尝试创建一个子图网格。每个子图将类似于此网站上的子图。
https://python-graph-gallery.com/24-histogram-with-a-boxplot-on-top-seaborn/
如果我有10个不同的这种类型的图,我想将它们变成一个5x2的图表。我已经阅读了Matplotlib的文档,但似乎无法弄清如何做到这一点。我可以循环子图并输出每个子图,但我无法将其制成行和列。
导入pandas和numpy库,以及seaborn库。
df = pd.DataFrame(np.random.randint(0,100,size=(100, 10)),columns=list('ABCDEFGHIJ'))
for c in df :
# Cut the window in 2 parts
f, (ax_box,
ax_hist) = plt.subplots(2,
sharex=True,
gridspec_kw={"height_ratios":(.15, .85)},
figsize = (10, 10))
# Add a graph in each part
sns.boxplot(df[c], ax=ax_box)
ax_hist.hist(df[c])
# Remove x axis name for the boxplot
plt.show()
结果将把这个循环中的数据放入一个行列集合中,本例中为5x2。