Seaborn jointplot颜色边缘图分别

Tom*_*ees 4 python matplotlib python-3.x seaborn

我想为每个变量分别为边际图着色。

d1 = np.random.normal(10,1,100)
d2 = np.random.gamma(1,2,100)
col1 = sns.color_palette()[0]
col2 = sns.color_palette()[1]
col3 = sns.color_palette()[2]

jp = sns.jointplot(d1, d2, kind="hex", annot_kws=dict(stat="r"), joint_kws=dict(bins='log'))
ax = jp.ax_joint
ax.plot(ax.get_xlim(), ax.get_ylim(), ls="--", c=".3", label="1:1")
Run Code Online (Sandbox Code Playgroud)

产生: 样例图

我想分别为每个边际图着色。但是,当我将参数分配给边界轴时,它们会用相同的参数给两个边界图上色。

jp = sns.jointplot(d1, d2, kind="hex", annot_kws=dict(stat="r"), joint_kws=dict(bins='log'), marginal_kws=dict(hist_kws= {'color': col2}))
ax = jp.ax_joint
ax.plot(ax.get_xlim(), ax.get_ylim(), ls="--", c=".3", label="1:1")

Run Code Online (Sandbox Code Playgroud)

对边际分布着色

我可以为“ facecolors”着色,但不能为轴本身着色。任何帮助非常感谢!

jp = sns.jointplot(d1, d2, kind="hex", annot_kws=dict(stat="r"), joint_kws=dict(bins='log'), marginal_kws=dict(hist_kws= {'color': col2}))
ax = jp.ax_joint
ax.plot(ax.get_xlim(), ax.get_ylim(), ls="--", c=".3", label="1:1")

# new code
jp.ax_marg_x.set_facecolor(col1)
jp.ax_marg_y.set_facecolor(col3)

Run Code Online (Sandbox Code Playgroud)

分别给脸色上色

She*_*ore 5

您可以通过访问两个边缘图的补丁并更改其脸色来完成此操作。

import seaborn as sns
import numpy as np

# define data here

jp = sns.jointplot(d1, d2, kind="hex", annot_kws=dict(stat="r"), joint_kws=dict(bins='log'), color=col2)
ax = jp.ax_joint
ax.plot(ax.get_xlim(), ax.get_ylim(), ls="--", c=".3", label="1:1")

for patch in jp.ax_marg_x.patches:
    patch.set_facecolor(col1)

for patch in jp.ax_marg_y.patches:
    patch.set_facecolor(col3) 
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明