python - 位于子图中的多个计数图中的 Seaborn 堆叠条
问题描述
有没有办法将条堆叠起来,countplot
所以每个条都包含两种颜色。
到目前为止我的代码:
fig, axes = plt.subplots(4, 4, figsize=(15,13), sharex=True)
axes = axes.flatten()
object_bol = df.dtypes == 'object'
for ax, catplot in zip(axes, df.dtypes[object_bol].index):
sns.countplot(y=catplot, data=df, ax=ax, hue = "Attrition")
plt.tight_layout()
plt.show()
下面是我当前的可视化以及我希望实现的堆叠图。
解决方案
您可以将关键字参数传递给plt.bar
from seaborn.countplot
。
因此,您可以使用该bottom
参数。例如(使用plt.bar
):
x = np.arange(0,11,1)
y = x**2
plt.bar(x, y)
plt.bar(x, y, bottom=y)
plt.xlabel('x')
plt.ylabel('y')
给出:
推荐阅读
- c# - 我正在尝试在一个类中创建一个方法,该方法将返回一个特定的字符串,但是当我运行控制台应用程序时没有返回任何内容
- php - 在 wordpress 主题中,我丢失的密码链接错误如何更改该链接?
- azure-devops - Azure 经典管道中的条件变量
- node.js - 在 git bash 中找不到 nodemon 命令
- pyspark - PySpark Couchbase 连接
- python - 列出我无法弄清楚的 Python 中的问题
- linux - N:忽略目录“/etc/apt/sources.list.d/”中的文件“yarn.lis”,因为它具有无效的文件扩展名
- ansible - 在多台服务器上循环命令后重新启动服务
- javascript - Node.js createWriteStream 'finish' 调用晚
- rust - 在 Rust 中模仿 Python 输入函数的惯用方式