gpt4 book ai didi

python - Seaborn jointplot 颜色边际图分别

转载 作者:太空狗 更新时间:2023-10-30 02:36:15 25 4
gpt4 key购买 nike

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

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

产生: Example Plot

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

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

Plot Colouring the Marginal Distributions

我可以为“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)

Coloring the facecolors individually

最佳答案

您可以通过访问两个边缘图的补丁并更改它们的面部颜色来实现。

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)

enter image description here

关于python - Seaborn jointplot 颜色边际图分别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55284426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com