Seaborn少了一箱直方图。这是海本的虫子,还是我的误用?

2024-04-20 08:11:16 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一段用matplotlib绘制直方图的代码

rng = np.random.RandomState(10)
a = rng.normal(size=10000)
# set width as {0.01, 0.02, 0.03}
_ = plt.hist(a, bins=9)

enter image description here

这是一段与seaborn绘制相同直方图的代码

sns.distplot(a, norm_hist=False, kde=False, bins=9, hist_kws={"alpha": 1})

当我添加一些设置以使绘图更好时:

sns.set(style='whitegrid', palette="deep", font_scale=1.1, rc={"figure.figsize": [8, 5]})
sns.distplot(a, norm_hist=False, kde=False, bins=9, hist_kws={"alpha": 1})

最右边的箱子不见了!你知道吗

enter image description here

这是海本的虫子,还是我的误用?你知道吗


Tags: 代码alphafalsenormmatplotlib绘制直方图hist
1条回答
网友
1楼 · 发布于 2024-04-20 08:11:16

您还应该在hist_kws中使用此参数'linewidth':0.1

sns.distplot(a, norm_hist=False, kde=False, bins=9, hist_kws={"alpha": 1, 'linewidth':0.1})

enter image description here

相关问题 更多 >