|
From: Travis E. O. <oli...@ie...> - 2006-01-25 19:01:42
|
Jeff Whitaker wrote:
> Stephens, A (Ag) wrote:
>
>
> Ag: You should be able to use either contourf or pcolor to make the
> plot by just passing it the X and Y coordinates of the radial distance,
> azimuth points. Here's a simple example:
>
> from pylab import *
> deltatheta = 2.*pi/100.
> theta = arange(0.,2.*pi,deltatheta)
> R = arange(0.,pi,deltatheta)
> r,t = meshgrid(R, theta)
I see this kind of code a lot on this list. I just want to point out
that in NumPy (and Numeric and Numarray) you don't have to completely
generate the "meshgrid" like this because of broadcasting. All you need
is for r to be Nx1 and t to be 1xN and the broadcasting will take care
of it so that Z, X, and Y below are all NxN. This can save space and
time particularly for large values of N.
In NumPy (and old SciPy) there is even a simple constructor for these
"open" grids:
r,t = ogrid[0:pi:deltatheta, 0:2*pi:deltatheta]
would replace the three lines above.
> Z = sin(r)*sin(3.*t)
> X = r*cos(t)
> Y = r*sin(t)
> figure(figsize=(8,8))
> cs = contourf(X, Y, Z)
> title('Simple polar contour plot')
> show()
Sorry for the somewhat off-topic post.
-Travis
|