Histogramme bug report

Hello All.
I just found a bug with the histogramme fonction of matplotlib.
It might been already known, in this case don’t pay attention to my message.

The bug append with both OS: Windows XP and Linux (ubuntu). Both using the latest matplotlib release: 0.99.1

The bug is reproductible, with the folliwng script:

What the script shall do:
Let’s say you are looking at the color of wagons on trains.
Every trains has 31 wagons.
Each time you see a red one, you write down it’s number
At the end, you want to draw the histogramme with
X axis: Number of the wagon in the tain
Y axis: Number of wagon of a specific number which is red.

My script

···

#------------------------------------------------------------------------------------------------------------------------------
import matplotlib.pyplot as
plt

liste_histo=[2,2,2,6,1,2,7,2,1,2,1,2,2,1,2,2,11,1,2,12,2,2,14,2,2,1,2,6,1,2,2]
plt.figure(1)
plt.hist(sorted(liste_histo),bins=31)
plt.axis([0,31,0,20])
plt.show()
#-----------------------------------------------------------------------------------------------------------------------------

This script should give you a srange historamme, with bins that are half the size they shoud be.

With the same script, but a different countdown of my wagons, it works well:
#-----------------------------------------------------------------------------------------------------------------------------
import matplotlib.pyplot as
plt

liste_histo=[2,2,2,6,1,2,7,2,1,2,1,2,2,1,2,2,11,1,2,12,2,2,14,2,2,1,2,6,15,25]
plt.figure(1)
plt.hist(sorted(liste_histo),bins=31)
plt.axis([0,31,0,20])
plt.show()
#-----------------------------------------------------------------------------------------------------------------------------

I corrected this error by adding a 32 (my max value on the histogramme should be a 31).
asking 32 bins, and drawing the histogramme between 1 and 31:

#------------------------------------------------------------------------------------------------------------------------------

import matplotlib.pyplot as plt

liste_histo=[2,2,2,6,1,2,7,2,1,2,1,2,2,1,2,2,11,1,2,12,2,2,14,2,2,1,2,6,1,2,2,32]

plt.figure(1)

plt.hist(sorted(liste_histo),bins=32)

plt.axis([0,31,0,20])

plt.show()

#-----------------------------------------------------------------------------------------------------------------------------

And it works…
Am I the only one to get a probleme here?

Thanks for reading me

Julien

I’m sorry but it is not clear what is wrong. The histogram looks just fine to me. Maybe you wanted to do

plt.hist(sorted(liste_histo),bins=range(31))

?

-JJ

···

On Tue, Mar 30, 2010 at 11:12 AM, Julien <ju_bicycle@…120…136…> wrote:

This script should give you a srange historamme, with bins that are half the size they shoud be.