强制使用cumulative=True的直方图的最后一个bin继续到matplotlib中的轴线

2024-05-03 10:07:08 发布

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

在python中绘制同一轴上的多个累积直方图时,我有一个美学问题。柱状图将以最后一个bin结束,而不是继续到终端轴。在

因此,当我绘制不同的总体图时,为了直观地显示一个KS统计数据,它最终看起来很平庸。ugly_histogram.png

编辑:根据汤姆的建议,最小工作代码。在

import pylab as pl
import random as rnd

x1 = [rnd.gauss(0,7) for a in range(100)]
x2 = [rnd.gauss(-3,1) for a in range(100)]
x3 = [rnd.gauss(3,3) for a in range(100)]

pl.hist(x1, cumulative=True, histtype='stepfilled', alpha=0.25)
pl.hist(x2, cumulative=True, histtype='stepfilled', alpha=0.25)
pl.hist(x3, cumulative=True, histtype='stepfilled', alpha=0.25)

pl.show()

从美学角度看,图像的柱状图应该在轴的两端延续,如维基百科的图片所示:

wikipedia KS test image


Tags: inalphatruefor绘制rangehistpl