MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: contour plot from a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37940] RE: [mg37923] contour plot from a list
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Wed, 20 Nov 2002 09:09:15 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Nadia Elghobashi [mailto:nadiae at chemie.fu-berlin.de]
To: mathgroup at smc.vnet.net
>Sent: Wednesday, November 20, 2002 2:59 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg37940] [mg37923] contour plot from a list
>
>
>
>Dear Mathematica,
>
>I have data of the form {x,y,z} which I would like to plot as 
>a contour 
>plot. I have read in the data as: 
>
>t=ReadList["file",Number,RecordLists->True];
>
>and would now like to make a simple contour plot of the z values on my 
>regularly spaced grid. The option 
>
>ListContourPlot[t]
>
>doesn't do the job. Could you help?
>
>Thank you, Nadia Elghobashi
>
>

Nadia,

you'r not telling enough to give a straight answer. So I try to give some
winded explanations on ListContourPlot. The First statement to be made can
be found under Help > ListContourPlot:

 "ListContourPlot[array] generates a contour plot from an array of height
values"

That is: a two dimensional array of z-values! But you have got a linear List
of {x,y,z} values, which has to be processed first.

Before doing so let us consider an example:

In[1]:= ContourPlot[Sin[x]*y,{x,0,Pi},{y,0,1}]

This gives a CountourGraphics, which is the same as from ListContourPlot of
the array

In[2]:= ca = Table[Sin[x]*y, {y, 0, 1, 1/(15 - 1)},
                             {x, 0, Pi, Pi/(15 - 1)}];

In[3]:= ListContourPlot[ca, MeshRange -> {{0, Pi}, {0, 1}}]

(Here 15 is the default value of PlotPoints, we used.)


Let us now assume we had got a corresponding list of {x,y,z} in an
unspecified order:

In[4]:= << DiscreteMath`Permutations`

In[5]:= xyza = Table[{x, y, Sin[x]*y}, 
                     {y, 0, 1, 1/(15 - 1)}, 
                     {x, 0, Pi, Pi/(15 - 1)}];

In[6]:= rl = Flatten[xyza, 1][[RandomPermutation[15*15]]]; 

We bring this into appropriate order and extract the ranges, to...

In[7]:= rls = Transpose[Partition[Sort[rl], 15]];

In[10]:= ListContourPlot[rls[[All,All,3]], 
           MeshRange -> {rls[[1,All,1]][[{1, -1}]], 
                         rls[[All,1,2]][[{1, -1}]]}]

...reconstruct the very same ContourGraphics.


If you happen to have your {x,y} pairs from a regular rectangular grid (and
have them all) this procedure (In[7] and In[10]) should work (you only have
to replace 15 with the correct number of PlotPoints (in x-direction), this
may be automated of course)) .

Else you may resort to a package from Tom Wickham-Jones, available from
http://www.mathsource.com/Content/Enhancements/Graphics/3D/0205-041

which extends ListContourPlot to allow plotting of irregular data:

In[13]:= << ExtendGraphics`Contour`

In[14]:= ListContourPlot[rl]

...gives you again the Contours, the ContourShading is missing however (TWJ
lacked to implement it, and the world is waiting for someone to fill in the
gap -- but it's not quite trivial however! (to find an efficient algorithm,
but perhaps a slow one is better than none. I think in one of the earliest
versions of Mathematica ContourPlot had been in an Add-on Package; if only
someone will pass it over, I'd have a look at it).)

Hope that helped.

--
Hartmut Wolf



  • Prev by Date: Re: named optional parameters
  • Next by Date: Re: Extracting a sub-list?
  • Previous by thread: Re: contour plot from a list
  • Next by thread: Interactivity?