【发布时间】:2021-11-29 10:54:23
【问题描述】:
我正在尝试绘制 ML 模型的预测输出,目标有 1,0 类和分数。由于数据集不平衡,所以很少有 1。
当我在色调参数中使用 Target 绘制一个简单的分布图时,该图对于描述 1 是无用的
sns.set_theme()
sns.set_palette(sns.color_palette('rocket', 3))
sns.displot(df, x='Score', hue='Target', bins=30, linewidth=0, height=5, kde=True, aspect=1.6)
plt.show()
我想在同一个图中更改 1 的比例,并在右侧使用 twinx 更改第二个 y 比例。
我尝试了以下代码,可能会解决 2 个图的问题,但 我只需要一个图。我无法使用 twinx。
g = sns.displot(df, x='Score', col='Target', bins=30, linewidth=0, height=5, kde=True, aspect=1.6, facet_kws={'sharey': False, 'sharex': False})
g.axes[0,1].set_ylim(0,400)
plt.show()
g = sns.FacetGrid(df, hue='Target')
g = g.map(sns.displot, 'Score', bins=30, linewidth=0, height=3, kde=True, aspect=1.6)
一个可重复的例子可能是泰坦尼克数据集:
df_ = sns.load_dataset('titanic')
sns.displot(df_, x='fare', hue='survived', bins=30, linewidth=0, height=5, kde=True, aspect=1.6)
g = sns.displot(df_, x='fare', col='survived', bins=30, linewidth=0, height=5, kde=True, aspect=1.6, facet_kws={'sharey': False, 'sharex': False})
g.axes[0,1].set_ylim(0,150)
plt.show()
【问题讨论】:
-
您是否查看了 displot 和相关函数的
common_norm=False选项? -
我认为seaborn histplot and displot output doesn't match 是相关的,但不是重复的。
标签: python seaborn histogram distribution