user2175414
user2175414

Reputation: 33

Matplotlib skips data -

I am trying to plot a bar chart using matplotlib. My issue is I have some "0" values in the list and matplotlib eats some of these values, how do I make sure it always plots all the values.

Here is the code:

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)

To make things more clear,
here are the values of pos : [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]

and values of counter_trim: [0, 0, 0, 1, 17, 6, 0, 14, 32, 11, 0, 0, 2, 0, 1, 0, 0]

The code above skips first 3 and last 2 zeros, but rest everything is same!

Any ideas how to avoid this?

Upvotes: 1

Views: 363

Answers (1)

Faultier
Faultier

Reputation: 1326

try out something like this:

plt.xlim(0, len(counter_trim))

as he is drawing no actual bar I guess the plot command omits these entries. I could not try it with your labels on x as they are not with the text but this worked with a standard axis.

Upvotes: 2

Related Questions