python的seaborn联合图,每个直方图的颜色不同 [英] python's seaborn jointplot, different colors for each histograms

查看:63
本文介绍了python的seaborn联合图,每个直方图的颜色不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改由 seaborn 创建的联合图中每个直方图的颜色.

I would like to change the colors for each histogram in a jointplot, created with seaborn.

我设法使用 margin_kws 更改了两个图的颜色,但是如何为每个直方图设置颜色?(例如红色和绿色直方图)

I managed to change the color for both plots using marginal_kws, but how can I set a color for one histogram each? (e. g. red and green histogram)

我的关节图的最小示例:

A minimal example of my jointplot:

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

x, y = np.random.multivariate_normal([2, 3], [[0.3, 0], [0,  0.5]], 1000).T

with sns.axes_style("white"):
  g = sns.jointplot(x=x, y=y, kind="hex", stat_func=None, marginal_kws={'color': 'green'})
plt.show()

推荐答案

iayork 关于直接使用轴对象的回答很好,尽管另一种选择是在绘图后更改条形的颜色:

iayork's answer about using the axes objects directly is good, although another option would be to change the color of the bars after plotting:

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="white", color_codes=True)

x, y = np.random.multivariate_normal([2, 3], [[0.3, 0], [0,  0.5]], 1000).T
g = sns.jointplot(x=x, y=y, kind="hex", stat_func=None, marginal_kws={'color': 'green'})
plt.setp(g.ax_marg_y.patches, color="r")

这篇关于python的seaborn联合图,每个直方图的颜色不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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