python - 使用 seaborn 循环轴以创建散点图
问题描述
我正在尝试使用目标变量和 9 个连续变量创建 9 个散点图。
我想不出一种方法来遍历每个轴以绘制每个连续变量对目标的散点图。
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(nrows=5, ncols=3, figsize=(16, 8))
sns.scatterplot(x=df['cont0'], y=df['target'], ax=ax[0, 0])
sns.scatterplot(x=df['cont1'], y=df['target'], ax=ax[0, 1])
sns.scatterplot(x=df['cont2'], y=df['target'], ax=ax[0, 2])
sns.scatterplot(x=df['cont3'], y=df['target'], ax=ax[1, 0])
sns.scatterplot(x=df['cont4'], y=df['target'], ax=ax[1, 1])
sns.scatterplot(x=df['cont5'], y=df['target'], ax=ax[1, 2])
sns.scatterplot(x=df['cont6'], y=df['target'], ax=ax[2, 0])
sns.scatterplot(x=df['cont7'], y=df['target'], ax=ax[2, 1])
sns.scatterplot(x=df['cont8'], y=df['target'], ax=ax[2, 2])
我怎样才能更有效地做到这一点?
解决方案
推荐阅读
- javascript - 无法在 Firestore 中设置状态添加承诺
- javascript - 如何隐藏多张图片只显示一张图片?
- php - 循环遍历一个表,每条记录都有另一个循环
- java - Java FX输入字段的错误异常处理,确保该字段只接受正整数
- typescript - 在 TypeScript 中,我可以根据索引器键的窄类型来限制索引器值的类型吗?
- ajax - JavaScript Ajax - Prevent Division by Zero Function
- powershell - PowerShell 分析变量和对象
- javascript - Yup validation decimal number
- r - R通过注释数据框替换列中的单词
- graphql - 如何创建远程 Hasura 服务器的本地“副本”?