python - 如何绘制seaborn中离散变量的分布图

标签 python matplotlib seaborn probability-distribution

当我为离散变量绘制 displot 时,分布可能不像我想的那样。例如。

enter image description here 我们可以发现 barplot 中存在裂缝,因此 kdeplot 中的曲线在 y 轴上“较低”。

在我的工作中,情况更糟: enter image description here

我认为这可能是因为每个条形图的“宽度”或“重量”不是 1。但是我没有找到任何可以证明它合理的参数。

我想画这样的曲线(应该更平滑) enter image description here

最佳答案

解决这个问题的一种方法可能是调整 KDE 的“带宽”(see the documentation for seaborn.kdeplot())

n = np.round(np.random.normal(5,2,size=(10000,)))
sns.distplot(n, kde_kws={'bw':1})

enter image description here

编辑 这里有一个不同规模的酒吧和 KDE 的替代方案

n = np.round(np.random.normal(5,2,size=(10000,)))
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()

sns.distplot(n, kde=False, ax=ax1)
sns.distplot(n, hist=False, ax=ax2, kde_kws={'bw':1})

enter image description here

关于python - 如何绘制seaborn中离散变量的分布图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48990594/

相关文章:

python - 什么是 struct.pack Python 中的 4sL 格式

python - Python 2.7 "wide-build"usc4 是否与某些库不兼容?

python - 标签尺寸或旋转Python Seaborn图

python - 在seaborn catplot中为每个类别添加从最小点到最大点的水平线

python - r/dailyprogrammer 的挑战#375 - 通过在每个数字上加一来打印一个新数字

python - 如何使用Azure定时器功能来运行python脚本?

python - GUI 中具有长进程的选项卡都调用同一个实例? [编辑-QThread 和 QObject 用于将对象传递到 GUI]

python - 如何使用 matplotlib 生成阴影区域

python-2.7 - 有什么方法可以在不绘制直方图的情况下使用 matplotlib.pyplot 创建直方图?

python - 如何使用 seaborn 生成高分辨率热图?