2013-03-19 61 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