1

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

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 的条形。我只想要那里的空闲空间。

我究竟做错了什么?

4

1 回答 1

1

如何将 0 更改为 0.0001 by numpy.clip()

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()

在此处输入图像描述

于 2013-03-19T11:30:54.310 回答