如何摆脱pylab直方图中的线条

时间:2013-08-11 01:30:47

标签: python matplotlib plot

我有这个简化的代码:

import numpy, pylab, random

data = [ random.gauss(1, 0.2) for x in range(1000) ]

fig = pylab.figure()
weights = numpy.ones_like(data)/float(len(data))
n, bins, patches =pylab.hist(data, bins=20, histtype='stepfilled', 
                             weights=weights)
pylab.xlim(min(bins), max(bins))
pylab.ylim(0, 1)
p, = pylab.plot(bins)
pylab.savefig("test.png")

情节如下:

test.png

那条绿线是什么?我该如何删除它?

1 个答案:

答案 0 :(得分:4)

那是因为你正在绘制y轴上的x轴的点(即绿线),你不需要plot()

import numpy, pylab, random

data = [ random.gauss(1, 0.2) for x in range(1000) ]

fig = pylab.figure()
weights = numpy.ones_like(data)/float(len(data))
n, bins, patches =pylab.hist(data, bins=20, histtype='bar', 
                         weights=weights)
pylab.xlim(min(bins), max(bins))
pylab.ylim(0, 1)
pylab.show()

enter image description here

相关问题