Seaborn совместный цвет окраинных участков отдельно - PullRequest
4 голосов
/ 21 марта 2019

Я хочу раскрасить свои маргинальные графики отдельно для каждой переменной.

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

Я могу покрасить «лицевые цвета»но не сами оси.Любая помощь очень ценится!

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

1 Ответ

5 голосов
/ 21 марта 2019

Вы можете сделать это, открыв участки двух маргинальных участков и изменив их цвет лица.

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...