Matplotlib: Histogram with bars inside grid lines...how??

Enigma Curry workbee at gmail.com
Wed Mar 29 19:28:52 EST 2006


I'm playing around with matplotlib for the first time. I'm trying to
make a very simple histogram of values 1-6 and how many times they
occur in a sequence. However, after about an hour of searching I cannot
make the histogram stay within the bounds of the grid lines.

Here is my example:

pylab.grid()
x_values=[1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
pylab.hist(x_values,6)
pylab.show()

This produced the following image:
http://enigmacurry.com/usenet/historgram-bars-not-in-grid-lines.png

Starting with bar number 2, it creeps into grid 1.. and finally with
bar number 5 it's almost entirely in grid 4.. how do I make the bars
stay in their own grid lines?

I can see that hist() is somehow derived from bar() ... so it appears
that hist() has some undocumented parameters. I tried specifiying
width=1 but that just squished all of the bars together.

Also, is there a more object-oriented graphing package for Python? (How
am I supposed to know that hist() is derived from bar() if the docs
don't show proper inheritance?)

Thanks!




More information about the Python-list mailing list