Ravexina
Ravexina

Reputation: 2848

Can't properly plot a bar for float numbers using matplotlib

I've got 50 float number in a variable named v, each one are related to a range between 0 to 10000 with the step of 200.

A sample of the numbers:

print(v[0:4])
[1.90432656848e-05, 0.0014909867739, 0.00886048514416, 0.0131592904038]

I need to display them as a bar chart:

p = plt.bar(range(0, 10000, 200), v)

And here is what I get:

enter image description here

However I'm able to show them using plot:

p = plt.plot(range(0, 10000, 200), v)

enter image description here

So what's that I'm doing wrong?

Upvotes: 1

Views: 4591

Answers (1)

pask
pask

Reputation: 927

Your problem is the width of the bars. The default width is 0.8, so with a step of 200 this is just too thin to display.

You can adjust the width of the bars with:

p = plt.bar(range(0, 10000, 200), v, width=100)

Upvotes: 2

Related Questions