pandas 如何在seaborn中使用'hue'参数绘制关节图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40419822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 02:21:07  来源:igfitidea点击:

How to plot a jointplot with 'hue' parameter in seaborn

pythonpandasmatplotlibseaborn

提问by Pablo

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.

如果在jointplot中实现了参数'hue'。

How can I do this?

我怎样才能做到这一点?

Maybe superposing two joint plots?

也许叠加两个联合情节?

回答by Romain

A simple alternative is to use seaborn.lmplot-- even if x and y histogram are not drawn.

一个简单的替代方法是使用seaborn.lmplot-- 即使未绘制 x 和 y 直方图。

sns.lmplot(x='total_bill', y='tip', hue='sex', data=tips, fit_reg=False)

enter image description here

在此处输入图片说明

回答by Mayou36

You can't, unfortunately

你不能,不幸的是

and it won't be implemented in the near future, because the simplicity of jointplot should be preserved.

并且近期不会实现,因为应该保留jointplot的简单性。

See here: https://github.com/mwaskom/seaborn/issues/365

见这里:https: //github.com/mwaskom/seaborn/issues/365

You can only do it halfway (without the hist for both classes): Plotting two distributions in seaborn.jointplot

你只能做到一半(两个类都没有历史):在 seaborn.jointplot 中绘制两个分布