假设我有一个30列的数据框架,前10列是各种收集数据的"平均值",接下来10列是"中间值",最后10列是"模式".例如,第1列是height_mean
,第10列是height_median
,第20列是height_mode
.第2列是weight_mean
,第11列是weight_median
,第21列是weight_median
.
height_mean | ... | height_median | ... | height_mode | ... |
---|---|---|---|---|---|
56 | ... | 58 | ... | 55 | ... |
我想创建一个10x3的子图,它取每个变量的平均值、中值和模式图,并相邻地绘制它们,这样子图的每一行都是一个新变量.因此,第一行子地块将有高度的平均值、中位数和模式图,第二行子地块将有重量的平均值、中位数和模式图,依此类推.
到目前为止,我已经有了这个,它按照列在数据帧中的顺序创建子图:
fig, axs = plt.subplots(10, 3, figsize=(20,20))
for count, ax in zip(df.columns, axs.ravel()):
df_data.loc[:,[count]].boxplot(ax=ax)
plt.show()
我try 过这样做,但没有成功:
for n, column in enumerate(df_columns):
# add a new subplot iteratively
ax = plt.subplot(10, 3, n + 1)
df_data.iloc[:,[n]].boxplot(ax=ax)
ax = plt.subplot(10, 3, n + 2)
df_data.iloc[:,[n+9]].boxplot(ax=ax)
ax=plt.subplot(10,3,n+3)
df_data.iloc[:,[n+19]].boxplot(ax=ax)