简体   繁体   English

Seaborn:distplot中的边缘不适合该图

[英]Seaborn: edges in distplot don't fit the plot

When using matplotlib and seaborn in Jupyter with Python 2.7.12, I noticed that the edges of the distplot I drew don't fit the plot correctly (cf. the 2 figures below). 在Jupyter和Python 2.7.12中使用matplotlib和seaborn时,我注意到我绘制的distplot的边缘无法正确拟合该图(请参见下面的两个图)。 At first I thought it was an issue with the code, but when trying the same code on someone else's laptop with the exact same versions of Jupyter and Python, the issue did not occur. 起初我以为这是代码问题,但是当在别人的笔记本电脑上使用完全相同的Jupyter和Python版本尝试相同的代码时,就没有发生此问题。 Could anyone point me in the right direction? 有人能指出我正确的方向吗?

wrong plot: 错误的情节:

错误的情节

right plot: 正确的情节:

正确的情节

I would gladly share the notebook with the code and the dataset, but since I am kind of new to sharing notebooks online, I do not know what the 'standard way to go' is. 我很乐意与代码和数据集共享笔记本,但是由于我是在线共享笔记本的新手,所以我不知道“标准方式”是什么。

Any help would be greatly appreciated. 任何帮助将不胜感激。

It looks to me like the difference between the two plots is the bandwidth of the kernel used to calculate the KDE. 在我看来,这两个图之间的区别是用于计算KDE的内核带宽。 Maybe there are different default values on both machines. 也许两台机器上都有不同的默认值。

Try to play with either the bw= or kernel= parameters ( documentation ). 尝试使用bw=kernel=参数( 文档 )。 Like so: 像这样:

fig,(ax1,ax2) = plt.subplots(2,1, figsize=(5,10))
x = np.random.randn(100)
sns.distplot(x, ax=ax1)
sns.distplot(x, kde_kws={'bw':5}, ax=ax2)

在此处输入图片说明

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

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