gpt4 book ai didi

python - 将背景颜色图的大小设置为 seaborn jointplot 中的轴大小

转载 作者:太空狗 更新时间:2023-10-30 01:08:04 24 4
gpt4 key购买 nike

我正在使用 seaborn 根据 this example 创建情节.

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

背景颜色没有正确改变: enter image description here

我如何修复背景颜色以填充整个绘图?

最佳答案

您需要告诉底层函数 (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))

瞧:

enter image description here

关于python - 将背景颜色图的大小设置为 seaborn jointplot 中的轴大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25937624/

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