如何在seaborn中绘制带有'hue'参数的联合图 [英] How to plot a jointplot with 'hue' parameter in seaborn

查看:37
本文介绍了如何在seaborn中绘制带有'hue'参数的联合图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要显示以下命令行的图:

导入 numpy 为 np,pandas 为 pd将 seaborn 作为 sns 导入;sns.set(style ="white",color_codes = True)提示= sns.load_dataset(提示")g = sns.jointplot(x="total_bill", y="tip", data=tips,hue='sex')

如果参数 'hue' 是在 Jointplot 中实现的.

我该怎么做?

也许会叠加两个联合情节?

解决方案

此功能已添加到

我还想为联合图中的核密度估计提供一个最小示例(二维

I would like to have the plot of the following command line:

import numpy as np, pandas as pd
import seaborn as sns; sns.set(style="white", color_codes=True)
tips = sns.load_dataset("tips")
g = sns.jointplot(x="total_bill", y="tip", data=tips, hue= 'sex')

if the parameter 'hue' was implemented in jointplot.

How can I do this?

Maybe superposing two joint plots?

解决方案

This functionality was added in the v0.11 Seaborn release in September 2020 (see e. g. the release blog post or the documentation).

The documentation now features a great example based on the penguins dataset:

penguins = sns.load_dataset("penguins")
sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species")

I further would like to give a minimal example for a Kernel density estimation in the joint plot (a 2d kdeplot):

# optional: sns.set(style='darkgrid')
data = {'x': [1, 2, 3, 4, 5, 6], 
        'y': [2, 4, 1.5, 4, 3, 5], 
        'class': ['1', '1', '1', '0', '0', '0']}
sns.jointplot(data=data, x='x', y='y', hue='class', kind='kde',
              fill=True, joint_kws={'alpha': 0.7})

这篇关于如何在seaborn中绘制带有'hue'参数的联合图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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