[SciPy-user] Re: Contour plots

Arnd Baecker arnd.baecker at web.de
Tue Jun 8 07:35:34 CDT 2004


On Tue, 8 Jun 2004, Bryan Cole wrote:

> On Mon, 07 Jun 2004 16:14:35 +0200, Nils Wagner wrote:
>
> > Dear experts,
>
> ... doesn't apply to me.

me neither, but still ...:

> > I want to compute
> >
> >   f(x,y) = log(abs(det(A(x+1j*y))))
> >
> > over a grid of x,y.
> >
> > How can I contour the result within scipy or matplotlib ?
> >
>
> I struggled with this a while back. You can plot pixmaps from 2D array
> data using either scipy.plt or matplotlib, but I don't think you can get
> contours. gplt (Gnuplot) can generate contours in 3D plots but I can't see
> a way to get a contour plot on 2D axes.

I think one trick was to use
  "set term table; set out "cont.dat" ; replot ; set out"
to write the contour data into the file cont.dat
(untested^TM).

> Gist can do contours but
> scipy.xplt is unix-only and anyway,

scipy.xplt does work under Windows (and apparently Mac support
is on it's way)
(In our class we have many students using scipy.xplt on Windows
more or less happily)


If you need the actual contour data: _maybe_
it is possible to use the (internal?) contour command as
done in gist.py in the routine `plfc`

   for i in range (n + 1) :
      [nc, yc, xc] = contour (array ( [vc [i], vc [i + 1]]), z)


> I couldn't get scipy.xplt to compile
> on my FC2-linux machine,

Maybe it is worth describing your problems with compiling
in more detail so that the experts could fix any issues ...

> so havn't tried it myself.
>
> There is a separate python interface to gist, PyGist
> (http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/software/python/pygist-1.5.18a.tar.gz)
> which works well. I've just been experimenting with it and it looks the
> best out-the-box plotting solution for contours so far. PyGist is also
> available for win32. The Gist command set is rather cryptic, however;

This one might help a bit:
http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/software/python/pygist_html/pygist.html


> matplotlib is much easier for normal 2D graphs IMHO.
>
> There's a PyGist example below.

If you replace "from gist import *"
by "from scipy.xplt import *"
it also works fine from scipy.xplt.


Best,

Arnd

> -------------------------
>
> from gist import *
> winkill(0)
> window(0, wait=1, style='boxed2.gs')
>
> ij = indices((20,20))/20.0 #make a grid
>
> x = ij[0]
> y = ij[1]
>
> def f(x,y): #or the function of your choice...
>     return sin(x**2) + cos(y**2)
>
> z = f(x,y)
>
> plc(z, y, x) #makes contour plot
>
> raw_input() #to stop python exiting
>



More information about the SciPy-user mailing list