python - 如何从 2 个不同的数据集中并排显示 seaborn 图?
问题描述
sns.set(style="darkgrid")
parm = azdias_under_20.columns.to_series(index=None).sample(3)
for y in parm:
sns.countplot(x=y, data=azdias_under_20)
plt.show();
sns.countplot(x=y, data=azdias_over_20)
plt.show();
如何从 2 个不同的数据集中并排显示 seaborn 图?请回答确切的细节,而不是子情节或其他来源的链接。
谢谢你。
ALTERSKATEGORIE_GROB ANREDE_KZ CJT_GESAMTTYP FINANZ_MINIMALIST FINANZ_SPARER FINANZ_VORSORGER FINANZ_ANLEGER FINANZ_UNAUFFAELLIGER FINANZ_HAUSBAUER FINANZTYP ... PLZ8_ANTG1 PLZ8_ANTG2 PLZ8_ANTG3 PLZ8_ANTG4 PLZ8_BAUMAX PLZ8_HHZ PLZ8_GBZ ARBEIT ORTSGR_KLS9 RELAT_AB
1 1.0 2 5.0 1 5 2 5 4 5 1 ... 2.0 3.0 2.0 1.0 1.0 5.0 4.0 3.0 5.0 4.0
2 3.0 2 3.0 1 4 1 2 3 5 1 ... 3.0 3.0 1.0 0.0 1.0 4.0 4.0 3.0 5.0 2.0
3 4.0 2 2.0 4 2 5 2 1 2 6 ... 2.0 2.0 2.0 0.0 1.0 3.0 4.0 2.0 3.0 3.0
4 3.0 1 5.0 4 3 4 1 3 2 5 ... 2.0 4.0 2.0 1.0 2.0 3.0 3.0 4.0 6.0 5.0
5 1.0 2 2.0 3 1 5 2 2
解决方案
像这样的东西应该工作:
from matplotlib import pyplot as plt
import seaborn as sns
# fill in azdias_under_20, azdias_over_20, parm, ....
# draw two plots, next to each other with the same x and y axis
for y in parm:
fig, (ax1, ax2) = plt.subplots(figsize=(12, 6), ncols=2, sharex=True, sharey=True)
sns.countplot(x=y, data=azdias_under_20, ax=ax1)
sns.countplot(x=y, data=azdias_over_20, ax=ax2)
plt.show();
推荐阅读
- python - 如何将此数据集拆分为训练集和验证集?
- python - 为什么我得到两个变量的 id 对于整数但不是浮点数?
- asp.net-core - ASP.NET Core 从 HTTP 重定向到 HTTPS 问题
- c# - 如何在 ASP.NET C# 中删除 cookie 并检查同一请求中 cookie 的状态
- android-room - 防止多个表更改时多次触发 Room Observable 查询
- docker - 如何将环境变量传递到 Jenkins 的 docker 容器中?
- html - 你如何解释“grid-template-columns: 1fr auto minmax(800px, 3fr) 1fr;”?
- reactjs - Next.js 中带有动态变量的脚本标签
- sql - 在 oracle 触发器中保存另一个表中的值
- exoplayer - Exoplayer 演示卡在缓冲状态