Pylab不会“绘制”高度为0的条形图

时间:2013-03-19 11:16:14

标签: python matplotlib

我正在尝试使用以下代码绘制条形图:

import pylab as p
first = ["2013-02-05", "2013-02-12", "2013-02-19", "2013-02-26", "2013-03-05", "2013-03-12"]

second = [0, 0, 0, 25, 35, 0]

fig = p.figure()
ax = fig.add_subplot(1,1,1)
N = len(second)
ind = range(N)
ax.bar(ind, second, facecolor='#777777', align='center', ecolor='black')
ax.set_xticklabels(first)
fig.autofmt_xdate()

结果在这里(抱歉,还不能发布图片):http://oi48.tinypic.com/vzxah3.jpg

如您所见,省略了值为0的条形。我想要那里的自由空间。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

如何通过numpy.clip()将0更改为0.0001?

import pylab as p
first = ["", "2013-02-05", "2013-02-12", "2013-02-19", "2013-02-26", "2013-03-05", "2013-03-12"]

second = [0.0, 0.0, 0, 25, 35, 0]

fig = p.figure()
ax = fig.add_subplot(1,1,1)
N = len(second)
ind = range(1, N+1)
ax.bar(ind, np.clip(second, 0.001, np.inf), facecolor='#777777', align='center', ecolor='black', )
ax.set_xticklabels(first)
fig.autofmt_xdate()

enter image description here