如何显示所有列的单独的箱线图?

时间:2020-04-24 07:40:52

标签: python dataframe matplotlib seaborn boxplot

当我尝试显示所有列的箱线图时,我使用了以下命令:

df_num.boxplot(rot=90)

enter image description here

但是正如您所看到的,这些框是如此之细,因为它们的范围不同,并且不应共享相同的y轴。我可以在盒子图中做下面的事情吗?谢谢! enter image description here

1 个答案:

答案 0 :(得分:0)

您可以这样进行操作(示例仅包括2列,但显然可以添加更多列):

fig, ax = plt.subplots(figsize=(12,6), ncols=2)
df_num["backers_count"].plot.box(ax=ax[0])
df_num["converted_pledged_amount"].plot.box(ax=ax[1]);

...或与Seaborn:

fig, ax = plt.subplots(figsize=(12,6), ncols=2)
sns.boxplot(data=df_num, y="backers_count", ax=ax[0])
sns.boxplot(data=df_num, y="converted_pledged_amount", ax=ax[1]);

如果要在3行3列的网格中显示它们,则可以将ncols=2位更改为nrows=3, ncols=3,然后代替ax=ax[0],{{ 1}}等,您将编写ax=ax[1]ax=ax[0,0]