### Tags: easiest, generate, graphs, histograms, interested, plots, plotting, programming, python, scatter, specifically, withcircles

# Plotting histograms, scatter plots in Python

On Programmer » Python

6,795 words with 9 Comments; publish: Tue, 29 Apr 2008 19:35:00 GMT; (200109.38, « »)

What is the easiest way to generate some plots and graphs in Python ?

Specifically interested in simple histograms and scatter plots with

circles and regression lines.

Thanks for your suggestions.

*http://python.questionfor.info/q_python_61227.html*

All Comments

Leave a comment...

- 9 Comments
- Dr. Colombes wrote:
> What is the easiest way to generate some plots and graphs in Python ?

> Specifically interested in simple histograms and scatter plots with

> circles and regression lines.

google('matplotlib')

google('gnuplot.py')

hth,

f

#1; Tue, 29 Apr 2008 19:37:00 GMT

- Dr. Colombes wrote:
- One module is Matplotlib, that seems to model the Matlab way of doing
things ... its at sourceforge.

Peter W.

At 02:18 PM 8/6/2004, Dr. Colombes wrote:

>What is the easiest way to generate some plots and graphs in Python ?

>Specifically interested in simple histograms and scatter plots with

>circles and regression lines.

>Thanks for your suggestions.

>--

>http://mail.python.org/mailman/listinfo/python-list

#2; Tue, 29 Apr 2008 19:38:00 GMT

- One module is Matplotlib, that seems to model the Matlab way of doing
- >>>>> "Colombes" == Colombes <DrColombes.python.questionfor.info.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.../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()

#3; Tue, 29 Apr 2008 19:39:00 GMT

- >>>>> "Colombes" == Colombes <DrColombes.python.questionfor.info.yahoo.com> writes:
- > What is the easiest way to generate some plots and graphs in Python ?
Pychart:

http://www.hpl.hp.com/personal/Yasushi_Saito/pychart/

#4; Tue, 29 Apr 2008 19:40:00 GMT

- > What is the easiest way to generate some plots and graphs in Python ?
Paramjit Oberoi wrote:

>

> Pychart:

> http://www.hpl.hp.com/personal/Yasushi_Saito/pychart/

The charts look good, but the source code links fail.

Colin W.

#5; Tue, 29 Apr 2008 19:41:00 GMT

- >> Pychart:
> The charts look good, but the source code links fail.

I just tried downloading it, and they seem to work for me...

#6; Tue, 29 Apr 2008 19:42:00 GMT

- >> Pychart:
- Colin J. Williams wrote:
>

> Paramjit Oberoi wrote:

> The charts look good, but the source code links fail.

I found it funny that the author makes a comment about poor PostScript quali

ty

in Gnuplot, touting his as an alternative. If the examples on that page are

to

be believed, that stuff looks like low-quality Excel-type business charts,

while Gnuplot has been producing publication quality EPS for a loooong time

(ask the many thousands of scientists using it since the early 90's).

I'd say that matplotlib is the _real_ contender to gnuplot today, not that t

oy

with horrible font scaling, no apparent real symbol/math support, ugly legen

d

boxes...

Best,

f

#7; Tue, 29 Apr 2008 19:43:00 GMT

- Colin J. Williams wrote:
- DrColombes.python.questionfor.info.yahoo.com (Dr. Colombes) wrote in message news:<d1f3d1d3.0408061018.137b600f.python.questionfor.info.pos
ting.google.com>...

> What is the easiest way to generate some plots and graphs in Python ?

> Specifically interested in simple histograms and scatter plots with

> circles and regression lines.

> Thanks for your suggestions.

For high quality scientific plot I suggest

ppgplot and plplot.

pgplot (original)

http://www.astro.caltech.edu/~tjp/pgplot/

ppgplot (python module)

http://efault.net/npat/hacks/ppgplot/

plplot

http://plplot.sourceforge.net/

#8; Tue, 29 Apr 2008 19:44:00 GMT

- DrColombes.python.questionfor.info.yahoo.com (Dr. Colombes) wrote in message news:<d1f3d1d3.0408061018.137b600f.python.questionfor.info.pos
- 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.python.questionfor.info.ace.bsd.uchicago.edu> wrote in message news:<mailman.1312.1091824333.

5135.python-list.python.questionfor.info.python.org>...

> 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.../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()

#9; Tue, 29 Apr 2008 19:45:00 GMT

- John, Peter et al: