Seaborn Boxplot的子图 [英] Subplot for seaborn boxplot

查看:236
本文介绍了Seaborn Boxplot的子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的数据框

import seaborn as sns
import pandas as pd
%pylab inline
df = pd.DataFrame({'a' :['one','one','two','two','one','two','one','one','one','two'], 'b': [1,2,1,2,1,2,1,2,1,1], 'c': [1,2,3,4,6,1,2,3,4,6]})

一个箱形图就可以了

sns.boxplot(  y="b", x= "a", data=df,  orient='v' )

但是我想为所有变量建立一个子图.我会

But i want to build a subplot for all variables. I do

names = ['b', 'c']
plt.subplots(1,2)
sub = []
for name in names:

    ax = sns.boxplot(  y=name, x= "a", data=df,  orient='v' )
    sub.append(ax)

我得到

如何解决?谢谢您的帮助

how to fix it? thanx for your help

推荐答案

我们创建带有子图的图形:

We create the figure with the subplots:

f, axes = plt.subplots(1, 2)

其中轴是每个子图的数组.

Where axes is an array with each subplot.

然后我们用参数ax告诉每个图要在哪个子图中.

Then we tell each plot in which subplot we want them with the argument ax.

sns.boxplot(  y="b", x= "a", data=df,  orient='v' , ax=axes[0])
sns.boxplot(  y="c", x= "a", data=df,  orient='v' , ax=axes[1])

结果是:

这篇关于Seaborn Boxplot的子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆