2013-03-19 64 views
1

我想繪製一個使用matplotlib的條形圖。我的問題是我有一些列表中的「0」值,matplotlib吃了一些這些值,我如何確保它總是繪製所有的值。Matplotlib跳過數據 -

下面是代碼:

counter_trim = counter[6:(len(counter)-6)] 
pos = np.arange(len(Test_names[6:])) 

width =.65 

ax = plt.axes() 
ax.set_ylabel('Number of failures') 
ax.set_title('Distribution of ABT failures') 
ax.set_xticks(pos + (width/2)) 

xtickNames= ax.set_xticklabels(Test_names[6:]) 

plt.setp(xtickNames, rotation=90, fontsize=10) 
plt.bar(pos, counter_trim, width, color='b') 

plt.tight_layout() 
print 'Distribution plot can be found here:' +image_filepath 
plt.savefig(image_filepath) 

爲了使事情更加清楚,
這裏是pos的值:[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]

和counter_trim的值:[0,0,0,1,17,6,0,14,32,11,0,0,2,0,1,0,0]

的代碼上面跳過前3和後2個零,但休息一切都是一樣的!

任何想法如何避免這種情況?

+0

您使用的是什麼版本的matplotlib?你能清理你的示例代碼,以便它可以運行(即,將你的示例數據放入snipit中,擺脫xlabel細節)?這對我來說就像一個臭蟲。 – tacaswell 2013-03-22 19:36:42

回答

2

嘗試這樣的事:

plt.xlim(0, len(counter_trim)) 

,因爲他是畫沒有實際的吧我猜劇情命令忽略這些條目。我不能用x上的標籤來嘗試它,因爲它們不是與文本相關的,但是這與標準軸一起工作。

+0

謝謝你的工作! – user2175414 2013-03-19 14:48:39

+2

我很高興聽到這個消息。也許標記爲解決方案然後(; – Faultier 2013-03-19 15:19:47