繁体   English   中英

将背景色图的大小设置为海底联合图中的轴大小

[英]Set up the size of backgound colour plot to the size of axes in seaborn jointplot

我正在使用seaborn根据此示例创建地块。

import numpy as np
import pandas as pd
import seaborn as sns
sns.set(style="white")

rs = np.random.RandomState(5)
mean = [0, 0]
cov = [(1, .5), (.5, 1)]
x1, x2 = rs.multivariate_normal(mean, cov, 500).T
x1 = pd.Series(x1, name="$X_1$")
x2 = pd.Series(x2, name="$X_2$")

g = sns.jointplot(x1, x2, kind="kde", size=7, space=0)

但是,当我将代码的最后一行更改为

g = sns.jointplot(x1, x2, kind="kde", size=7, space=0, xlim=(-5,5), ylim=(-5,5))

背景颜色未正确更改: 在此处输入图片说明

如何固定背景色,使其充满整个图?

您需要告诉基础函数( kdeplot )将其KDE估计进一步扩展。 这是通过cut参数实现的,该参数是KDE带宽的函数。 它的默认值为3,并且没有明显的方法可以确切地告诉您需要如何设置它,但是尝试并找到有效的值并不难。 使用jointplot ,您需要在joint_kws字典中传递它,以便将其发送到适当的绘图函数。

sns.jointplot(x1, x2, kind="kde", size=7, space=0,
              joint_kws={"cut": 10},
              xlim=(-5,5), ylim=(-5,5))

瞧:

在此处输入图片说明

这很接近,但是我不能完全匹配颜色。 如果在cm模块中找到了颜色图(“凉”?),则可以找到确切的颜色。

ax = plt.gcf().axes[0]
ax.set_axis_bgcolor((.93,.93,1))

如果以交互方式进行此操作,则将需要plt.draw()来显示新的颜色。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM