gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:01:57 34 4
gpt4 key购买 nike

当我为离散变量绘制 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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com