python - 为什么 distplot 改变绘制值的范围?
问题描述
我有一个值数组,我试图为其拟合概率密度函数。我使用 distplot 绘制了直方图,如下所示:
x = [ 17.56,
162.52,
172.58,
160.82,
182.14,
165.86,
242.06,
135.76,
122.86,
230.22,
208.66,
271.36,
122.68,
188.42,
171.82,
102.30,
196.40,
107.38,
192.35,
179.66,
173.30,
254.66,
176.12,
75.365,
135.78,
103.66,
183.50,
166.08,
207.66,
146.22,
151.19,
172.20,
103.41,
133.93,
186.48,]
sns.distplot(x)
我在数组中的最小值是 17,最大值是 250 左右,所以我不明白图中 x 轴的范围,因为我也没有添加任何参数。sns.displot
绘图前是否对数据进行标准化?
解决方案
kde 曲线在数据点上拟合许多高斯正态曲线。这样一条法线曲线有一条无限的尾巴,当它足够接近零高度时,它就会被切断。
请注意,自 seaborn 0.11 以来sns.distplot
已弃用,并由 (在这种情况下) 取代sns.histplot(..., kde=True)
。新的kdeplot有一个cut=
默认为零的参数,在数据限制处切割曲线(cut
是kde_kws
in之一histplot
)sns.histplot(x, kde=True, kde_kws={'cut': 0}).
。
import seaborn as sns
x = [17.56, 162.52, 172.58, 160.82, 182.14, 165.86, 242.06, 135.76, 122.86, 230.22, 208.66, 271.36, 122.68, 188.42,
171.82, 102.30, 196.40, 107.38, 192.35, 179.66, 173.30, 254.66, 176.12, 75.365, 135.78, 103.66, 183.50, 166.08,
207.66, 146.22, 151.19, 172.20, 103.41, 133.93, 186.48]
sns.histplot(x, kde=True)
推荐阅读
- php - 会话被随机销毁
- c - 整数除以宏定义的其他整数常量在C中返回不正确?
- r - 在绘图中将文本悬停在 geom_segment 上
- jquery - 如何在数据绑定事件期间禁用某些网格行的单击和悬停?
- javascript - Javascript中“空”和“未定义”的区别?
- python - 将访问表读入数据框
- python - 适用于 python2.7 的 Google Sheets API -->“无效的 JSON 有效负载。根元素必须是消息”
- java - Hibernate 不创建表 - Spring Boot
- php - 使用PHP中数组中的值替换字符串中的文本
- java - JDK 9 兼容性