2013-03-19 36 views
1

我想畫一個柱狀圖用下面的代碼高度:Pylab不「畫」條帶的0

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更改爲0.0001通過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() 

enter image description here

+0

沒有這麼漂亮我想,但它的作品。謝謝。 – Matthew 2013-03-19 15:21:22