Matplotlib: Histogram with bars inside grid

Enigma Curry workbee at
Thu Mar 30 05:48:58 CEST 2006

Thank you John. Your explanation helped a lot!

In case it helps anyone else in the future, here is my code for
*exactly* what I was after:

import pylab

def ryan_hist(data, bar_width, min_x, max_x):
    Create a frequency histogram over a continuous interval

    min_x = the low end of the interval
    max_x = the high end of the interval

    bar_width = the width of the bars

    This will correctly align the bars of the histogram
    to the grid lines of the plot
    #Make histogram with bars of width .9 and center
    #them on the integer values of the x-axis
    bins = pylab.nx.arange(1-(bar_width/2),max(data))
    n,bins,patches = pylab.hist(data, bins, width=bar_width)

    #Make Y axis integers up to highest n

#Create a historgram
bar_width = 0.9

More information about the Python-list mailing list