我正在尝试使用matplotlib绘制条形图。我的问题是我在列表中有一些"0“值,而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个零,但其余的都是一样的!
有什么办法可以避免这种情况吗?
发布于 2013-03-19 22:40:18
试试下面这样的代码:
plt.xlim(0, len(counter_trim))由于他没有绘制实际的条形图,我猜plot命令省略了这些条目。我不能尝试在x上使用你的标签,因为它们不是与文本一起使用的,但这与标准轴一起工作。
https://stackoverflow.com/questions/15502161
复制相似问题