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

python';s seaborn jointplot,每个直方图的颜色不同,python,seaborn,Python,Seaborn,我想更改使用seaborn创建的jointplot中每个直方图的颜色 我设法用边线改变了两个图的颜色,但是如何为每个直方图设置颜色呢?(如红色和绿色直方图) 我的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

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

我设法用边线改变了两个图的颜色,但是如何为每个直方图设置颜色呢?(如红色和绿色直方图)

我的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()
我认为您需要使用而不是在这里。这是一个试图接近你现在的情节的尝试;您可能需要更多地使用颜色和CMAP,以使hexbin绘图更具吸引力

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

def hexbin(x, y): 
    plt.hexbin(x, y, gridsize=20, cmap='Blues')

with sb.axes_style("white"):
    g = sb.JointGrid(x=x, y=y, ylim=(0,6))
    g = g.plot_joint(hexbin)
    g.ax_marg_x.hist(x, color="b", alpha=.6) 
    g.ax_marg_y.hist(y, color="r", alpha=.6, orientation="horizontal")

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

我认为这种方法在将来会有更大的灵活性。它允许用户不仅改变颜色,还可以根据直方图设置不同数量的箱子,或者为箱子指定特定范围。