根据这个例子,我使用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)
Run Code Online (Sandbox Code Playgroud)
但是,当我将最后一行代码更改为
g = sns.jointplot(x1, x2, kind="kde", size=7, space=0, xlim=(-5,5), ylim=(-5,5))
Run Code Online (Sandbox Code Playgroud)
背景颜色未正确更改:

我如何修复背景颜色以填充整个情节?
你需要告诉底层函数(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))
Run Code Online (Sandbox Code Playgroud)
瞧:
