[GRASS-dev] Python MatPlotLib histogram example
Michael Barton
michael.barton at asu.edu
Wed Jan 30 00:55:04 EST 2008
I spent a little time playing around with the Python statistical
graphing library MatPlotLib this evening. I've attached a screenshot
of a demo histogram and, below, the code needed to create it. This
example uses TkInter, but it isn't much more complicated to put this
into wxPython. This seems pretty cool. There are much nicer plots too.
Michael
____________________
C. Michael Barton, Professor of Anthropology
Director of Graduate Studies
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University
Phone: 480-965-6262
Fax: 480-965-7671
www: <www.public.asu.edu/~cmbarton>
======== example code =======
#!/usr/bin/env python
from pylab import *
mu, sigma = 100, 15
x = mu + sigma*randn(10000)
# the histogram of the data
n, bins, patches = hist(x, 50, normed=1)
setp(patches, 'facecolor', 'g', 'alpha', 0.75)
# add a 'best fit' line
y = normpdf( bins, mu, sigma)
l = plot(bins, y, 'r--')
setp(l, 'linewidth', 1)
xlabel('Smarts')
ylabel('Probability')
title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
axis([40, 160, 0, 0.03])
grid(True)
#savefig('histogram_demo',dpi=72)
show()
===== graph generated by this code ===========

-------------- next part --------------
Skipped content of type multipart/related
More information about the grass-dev
mailing list