限制 kdeplot 上的 xlim,同时保持其平滑

Restrict xlim on kdeplot while keeping it smooth

下面的 kdeplot 在左边有一个峰,我想把更多的重点放在上面:

a = np.array([1] * 100 + [5])
sns.kdeplot(a)

我常用的方法是 pyplot.xlim 调用,但是对于这样的分布,放大到这么多会显示出锯齿状的曲线,这与典型的平滑 kde 曲线不同:

plt.xlim(.5, 1.1)
sns.kdeplot(a);

有什么方法可以通过 kdeplot 来限制 x 轴以保持平滑度吗?

seaborn.kdeplot 接受默认为 100 的 gridsize 参数,代表 "Number of discrete points in the evaluation grid"。提高这个数字应该会在放大视图中提供更多细节,就像您想要的那样:

sns.kdeplot(a, 500)