       RE: Plotting a contour plot with cylindrical co-ordinates

• To: mathgroup at smc.vnet.net
• Subject: [mg49498] RE: [mg49468] Plotting a contour plot with cylindrical co-ordinates
• From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
• Date: Thu, 22 Jul 2004 02:45:12 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```>-----Original Message-----
>From: Jake [mailto:luckyjake3000 at yahoo.com]
To: mathgroup at smc.vnet.net
>Sent: Wednesday, July 21, 2004 12:40 PM
>To: mathgroup at smc.vnet.net
>Subject: [mg49498] [mg49468] Plotting a contour plot with cylindrical
>co-ordinates
>
>
>I have a set of data which corresponds to points on a circle. I have
>these values as a function of r and theta. Is there a way of plotting
>this in Mathematica? The ContourPlot function requires x and y
>co-ordinates.
>thanks.
>
>

I understand that r is not the same for all your data.

It all depends on how your data are sampled.

If you have equidistant sampling for r and phi, e.g. as in

pts2 = Table[Sin[2 Pi r^2], {r, 0, 1, .1}, {phi, 0, 2 Pi, 2 Pi / 48}];

Then you may generate a ListContourPlot in {r, phi} space, and then transform the resulting Graphics back to {x, y} space and display.

g = Graphics[ListContourPlot[pts2, ContourShading -> True],
PlotRange -> {-1, 1}]

{s1, s2} = Dimensions[pts2] - 1

g2 = g /. {phi_Real,
r_Real} :> (r - 1)/s1  Through[{Cos, Sin}[2 Pi (phi - 1)/s2]]

g2c = Show[MapAt[Reverse, Delete[g2, {1, 1}], 1]]

The tricky point here is to get the order of the layers of Polygons right (also I removed a degenerate Polygon -- which prior had represented the background).  (To do this in a general way, effectively and efficiently, is a programming challenge.)

You might compare the result with an ordinary ContourPlot in {x, y} space:

pts1 = Table[Sin[2 Pi (x^2 + y^2)], {x, -1, 1, .1}, {y, -1, 1, .1}];

g1 = ListContourPlot[pts1, MeshRange -> {{-1, 1}, {-1, 1}}, PlotRange -> {-1, 1}]

Generally, you might try the package

<< ExtendGraphics`Contour`

pts3 =
Flatten[Block[{phidel = 2 Pi/ (120 r), rdel = 1/10},
Table[{r Sin[t], r Cos[t], Sin[2 Pi r^2]},
{r, rdel, 1, rdel},
{t, 0, 2 Pi - phidel, phidel}]], 1];

(g3 = ListContourPlot[pts3])//Timing

ExtendGraphics by Tom Wickham-Jones is available for free at MathSource from the WRI web site.

It lacks ContourShading (thus avoiding the challenge mentioned).  It is based on a Delaunay triangulation of the points (clearly you must supply the full coordinates, as you see from the example). That however might be numerically unstable and also run into very long loops (if there are many nearby points).

You may compare the last result with

Show[g2c /. Polygon[_] -> {}]

The (default) countour lines are not quite the same, perhaps someone already has had a look at this (I haven't got the time).

Well, as countour lines are derived from interpolated data (and this interpolation is different for all the three cases above) this not so much a surprise. Overlaying the graphics (with different colours however indicates larger differences than perhaps tolerable. (If I leave out the points with r == 0 -- and adapt the calculation of the coordinates appropriatly -- I get fairly consistent results with g1 and g2c, but not with g3).

So this post is not at all an answer, but an encouragement for study.

--
Hartmut Wolf

```

• Prev by Date: AW: Plotting a function and its derivative
• Next by Date: Re: rounding
• Previous by thread: RE: Plotting a contour plot with cylindrical co-ordinates
• Next by thread: MatrixManipulation package doesn't know how to handle SparseArrays?