Histogram with uneven heights within bins
<p>Why does my histogram look like this? I'm plotting it using the following code:</p>

<pre><code>import matplotlib.pyplot as plt

n, bins, patches = plt.hist(data, 25)
plt.show()
</code></pre>

<p>where <code>data</code> contains about 500,000 sorted points. Shouldn't each bin be smooth at the top?</p>

<p><a href="http://i.stack.imgur.com/fL8hB.png" rel="nofollow"><img src="http://i.stack.imgur.com/fL8hB.png" alt="enter image description here"></a></p>

<p>I suspect your data might not be a flat list, but, e.g., a list of lists or similarly structured. In that case, <code>hist</code> will bin by sublist. This script demonstrates the difference:</p>

<pre><code>import random
from matplotlib import pyplot as plt

data = [[random.randint(0, x) for x in range(20)] for y in range(100)]

plt.subplot(211)
# structured
plt.hist(data, 25)

plt.subplot(212)
# flattened
plt.hist([i for l in data for i in l], 25)

plt.show()
</code></pre>

<p>You will probably have to use some kind of similar "flattening" on your data.</p>

python matplotlib