首页 > 解决方案 > 修改正 x 的直方图曲线

问题描述

我有一些直方图代码如下:

plt.subplots(figsize=(10,8), dpi=100)
sns.distplot(x1, color='k', label='a',norm_hist = True)
sns.distplot(x2, color='g', label='b',norm_hist = True)
sns.distplot(x3, color='b', label='b',norm_hist = True)
sns.distplot(x4, color='r', label='c',norm_hist = True)
sns.distplot(x5, color='y', label='c',norm_hist = True)

对于我的数据,我得到了这个图 在此处输入图像描述

这很好,但我真正想要的是仅在正 x 值上拟合曲线。负持续时间没有物理意义。有什么选择吗?

标签: pythonpandashistogram

解决方案


sns.distplot()文档中:

...它还可以拟合 scipy.stats 分布并在数据上绘制估计的 PDF。

因此,您可以选择对您的数据有意义的非负分布,并使用fit参数传递适合您数据的SciPy 分布对象。

例如:

import seaborn as sns
from scipy import stats
iris = sns.load_dataset('iris')
sns.distplot(iris.petal_length, color='k', fit=stats.expon, kde=False)

在此处输入图像描述


推荐阅读