python的seaborn jointplot,每个直方图的颜色不同

标签 python seaborn

我想更改使用 seaborn 创建的联合图中每个直方图的颜色。

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

我的联合图的一个最小示例:

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()

enter image description here

最佳答案

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

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")

enter image description here

关于python的seaborn jointplot,每个直方图的颜色不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32046029/

相关文章:

python - 如何将数据标签添加到seaborn countplot/factorplot

python - Seaborn 线图高 CPU;与 matplotlib 相比非常慢

python - 如何使用 Python 将 blob 数据移动到 Snowflake

python - 如何在 discord.py cogs 中创建别名?

python - 在 Sublime Text 3 中只构建一行 - python

python - 无法使用 Seaborn 进行绘图

python - 我有每日数据。如何将蜱虫限制在几个月内?

python - 在 Python 中使用请求查询字符串数组参数

python - 从 python scipy.optimize.curve_fit 得到完全错误的拟合

python - seaborn plot_marginals 多个 kdeplots