Python - creating a histogram
Question: I'm using data of the form: `[num1,num2,..., numk]` (an array of integers).

I would like to plot a histogram of a particular form, which I will use an
example to describe.

Suppose `data = [0,5,7,2,3]`. I want a histogram with:

  * Bins of width 1.
  * x-axis ticks at 0,1,2,...,4 (one for each element of the array, e.g. if the array had 10 elements the ticks would run from 0 to 9)
  * For the bin between tick i and i+1, we have frequency (height) equal to `data[i] + data[i+1]`, e.g. between 1 and 2 we have a rectangle of height 12.

How do I create such a histogram using matplotlib? Or numpy, if you prefer.


Answer: histogram usage is e.g. here:

<http://matplotlib.org/examples/api/histogram_demo.html>

<http://matplotlib.org/examples/pylab_examples/histogram_demo_extended.html>

I'd create this special data structure you want beforehand, then feed it into
the histogram:

    
    
    map(int.__add__, data[1:], data[0:-1])
    > [5, 12, 9, 5]
    

If you already have numpy imported, you can also do

    
    
    a=numpy.array(data[0:-1])
    b=numpy.array(data[1:])
    a+b
    > array([ 5, 12,  9,  5])
    

