Plotting histograms, scatter plots in Python
Dr. Colombes
DrColombes at yahoo.com
Tue Aug 10 18:03:00 CEST 2004
John, Peter et al:
Thanks very much for your useful tips on MathPlotLib.
I've begun using MatPlotLib and I like it.
Others suggested GnuPlot, which I hope to try sometime in the
future.
Thanks all. This is a good example of very useful information
exchanged over an Internet newsgroup.
Dr. Colombes
John Hunter <jdhunter at ace.bsd.uchicago.edu> wrote in message news:<mailman.1312.1091824333.5135.python-list at python.org>...
> >>>>> "Colombes" == Colombes <DrColombes at yahoo.com> writes:
>
> Colombes> What is the easiest way to generate some plots and
> Colombes> graphs in Python ? Specifically interested in simple
> Colombes> histograms and scatter plots with circles and regression
> Colombes> lines.
>
> Here's a little example of a histogram and regression plot using
> matplotlib - looks easy enough to me! Output image at
> http://nitace.bsd.uchicago.edu:8080/files/share/demo.png
>
> from matplotlib.matlab import *
>
> x = randn(10000) # some gaussian noise
>
> subplot(211) # a subplot
> hist(x, 100) # make a histogram
> grid(True) # make an axes grid
> ylabel('histogram')
>
> # now do the regression...
> x = arange(0.0, 2.0, 0.05)
> y = 2+ 3*x + 0.2*randn(len(x)) # y is a linear function of x + nse
>
> # the bestfit line from polyfit
> m,b = polyfit(x,y,1) # a line is 1st order polynomial...
>
> # plot the data with blue circles and the best fit with a thick
> # solid black line
> subplot(212)
> plot(x, y, 'bo', x, m*x+b, '-k', linewidth=2)
> ylabel('regression')
> grid(True)
>
> # save the image to hardcopy
> savefig('demo')
> show()
More information about the Python-list
mailing list