繁体   English   中英

seaborn 中的多个计数图

[英]Multiple count plots in seaborn

我有一个 CSV 文件,它有多个列,现在我正在尝试 plot 并排计数 plot 为选定的列,使用下面的代码,我只能添加两列,在职的。 如何 plot 多个选定的列和 plot 并排。 当我绘制两个图表时,它的重叠,如何增加差距。

import pandas as pd 
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns

train_data = pd.read_csv(r"train_ctrUa4K.csv")

plt.figure(figsize=(10, 8))
fig, ax =plt.subplots(1,2)
sns.countplot(train_data['Gender'], ax=ax[0])
sns.countplot(train_data['Dependents'], ax=ax[1])
#sns.countplot(train_data['Self_Employed'], ax=ax[1])
#sns.countplot(train_data['Property_Area'], ax=ax[1,1])

fig.show()  

在此处输入图像描述

将调用中的列数更改为subplots()

fig, ax = plt.subplots(1,4)
sns.countplot(train_data['Gender'], ax=ax[0])
sns.countplot(train_data['Dependents'], ax=ax[1])
sns.countplot(train_data['Self_Employed'], ax=ax[2])
sns.countplot(train_data['Property_Area'], ax=ax[3])

如果您有太多的子图无法容纳在一行上,您也可以增加行数。 请注意,如果您有多于一行和多于一列,那么变量ax将是一个二维数组:

fig, ax = plt.subplots(2,2)
sns.countplot(train_data['Gender'], ax=ax[0,0])
sns.countplot(train_data['Dependents'], ax=ax[0,1])
sns.countplot(train_data['Self_Employed'], ax=ax[1,0])
sns.countplot(train_data['Property_Area'], ax=ax[1,1])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM