title: Histogram with percentage bins in Python/numpy?
body: <p>I need to create a histogram with percentage bins from a 2D set of data, like this (this is basically a set of reports from various devices, each line is a device reporting its status for a given hour):</p>
  
  <pre><code># hour # parameter (in percents)
  00     10
  00     20
  00     30
  01     40
  01     50
  ...
  </code></pre>
  
  <p>so that there would be a stacked histogram summary of the devices' reports binned by hour and percentile, just like the gnuplot example below, with bins representing the percentiles the reports fall into (say 0 &lt; r &lt; 10%, 10% &lt; r &lt; 20% and so on).</p>
  
  <p><a href="https://i.stack.imgur.com/SBuMn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SBuMn.png" alt="enter image description here"></a></p>
  
  <p>Right now I've only thought about creating a 2D array and feeding it all to gnuplot like this:</p>
  
  <pre><code>#!/usr/bin/python
  
  import numpy as np
  import sys
  
  data = np.loadtxt('mac-quality.csv')
  out = [ [ 0 for k in xrange(10) ] for i in (xrange(24) ) ]
  
  for i in data:
      hour = i[0].astype(int)
      quality = i[1].astype(int)
      for bin in xrange(10):
          pct = bin * 10
          if quality &gt; pct and quality &lt; (pct + 10):
              print('Data: %s, H: %s Percentile: %s:') % (i, hour, pct)
              out[hour][bin] += 1
  # print(out)
  </code></pre>
  
  <p>What would be the correct way of generating these histograms from within python?</p>