The bin count displayed by pyplot hist doesn't match the actual counts?
<p>I have a list of ints--I call it 'hours1'--ranging from 0-23. Now this list is for 'hours' of a day in a 24 hour clock.  I, however, want to transform it to a different time zone (move up 7 hours).  This is simple enough, and I do it so that now I have 2 lists: hours1 and hours2.</p>

<p>I use the following code to plot a histogram:</p>

<pre><code>bins = range(24)
plt.hist(hours,bins=bins, normed=0, facecolor='red', alpha=0.5)
plt.axis([0, 23, 0, 1000])
</code></pre>

<p>it works perfectly for hours1.  For hours2 the last value (that of the bin for 23s) is too high.  This is not a counting error/transformation error because when I count my hours2 list, I get 604 23s, which matches the what I expect (having 604 16s in hours1).</p>

<p>so this is a very long winded way of saying, the height of the bins do not match what I get when I count the data myself...</p>

<p>The issue was a binning one.  In short, I wasn't paying attention/thinking about what I wanted to display.  More specifically this was the correct code:</p>

<pre><code>bins = range(25)
plt.hist(hours, normed=0, facecolor='green', alpha=0.5, bins=bins)
plt.axis([0, 24, 0, 1500])
</code></pre>

<p>that is, there are 23 hours in a day, which means 24 seperate 'hour bins' counting 0.  but the correct edge values for this are bins = range(25) (so that 23 gets placed in 23-24) and the correct axis is 0 to 24, (so bin 23 has width of 1).  simple mistake, but i guess we've all bin there and done that?</p>

python matplotlib