带有两类的Seaborn对线非对角KDE [英] Seaborn pairplot off-diagonal KDE with two classes

查看:34
本文介绍了带有两类的Seaborn对线非对角KDE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查看两个不同类别变量的 Seaborn 配对图,我希望在非对角线上看到 KDE,而不是散点图.该文档有

如您所见,数据足够密集,很难看出非对角线上红色和蓝色数据的差异.

解决方案

您可能会这样说:

导入 seaborn 为 sns导入matplotlib.pyplot作为pltiris = sns.load_dataset("iris")g = sns.PairGrid(iris,hue ="species",hue_kws = {"cmap":["Blues","Greens","Reds"]})g = g.map_diag(sns.kdeplot, lw=3)g = g.map_offdiag(sns.kdeplot,lw = 1)plt.show()

I'm trying to look at a Seaborn pairplot for two different classes of variables and I'd like to see KDEs on the offdiagonals instead of scatterplots. The documentation has instructions on how to do a KDE for all of the data, but I want to see separate KDEs for each subclass of data. Suggestions welcome!

My code looks something like this:

plot = sns.pairplot(
    df,
    vars=labels,
    hue='has_accident',
    palette='Set1',
    diag_kind='kde',
)

which results in:

As you can see the data are sufficiently dense that it is difficult to see the difference in the red and blue data on the off diagonal.

解决方案

You possibly mean something like this:

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

g = sns.PairGrid(iris, hue="species", hue_kws={"cmap": ["Blues", "Greens", "Reds"]})
g = g.map_diag(sns.kdeplot, lw=3)
g = g.map_offdiag(sns.kdeplot, lw=1)

plt.show()

这篇关于带有两类的Seaborn对线非对角KDE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆