MathGroup Archive 1997

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

Search the Archive

Re: Contour Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5805] Re: Contour Plot
  • From: Robert Villegas <villegas>
  • Date: Wed, 22 Jan 1997 00:44:12 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

>   I use the command:
>
>     ContourPlot[f,{x,0,1000},{y,0,1000},Contours->{0}]
>
>   i.e, find f=0
>
>   How can I get the locations {{x1,y1},{x2,y2},{x3,y3},.....{xn,yn}}
>   when f=0?


Here is a reply I sent to essentially the same query that came up in
March of last year.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
In article <4h3l3v$1od at dragonfly.wolfram.com> easther at cfi.waseda.ac.jp
(Richard Easther) writes:

> Can someone help me with the following problem. After doing a
>
>        figure =  ContourPlot[f[x,y], ..., Contours ->{0}],
>
> I want to extract the set of points actually plotted - ie a set of {x,y}
> where f[x,y] == 0 for some additional processing.
>
> The command TextForm[InputForm[Graphics[ figure ]]] gives me a text
> string which has a series of Line commands that actually contains the
> {x,y} values that are plotted.
>
> Now what I want to know is this: can someone tell me a nice (or even
> ugly but workable!) way of extracting the list(s) of points plotted by
> the Line command(s)?


You're most of the way there with Graphics[figure].  That contains the
Line objects, as you noted, so all that's left to do is extract them:

contourLines = Cases[Graphics[figure], _Line, -1]

This returns a list of Line objects that comprise the level curve
z = 0.  There might be more than one if the contour is disconnected
(at least, disconnected in the rectangle in which f was originally
plotted), or none.

And if you want a different level curve z = z0 later on, just Show
'figure' again with a different Contours setting.

contourLines =
  Cases[Show[figure, Contours->{z0}, DisplayFunction->Graphics,
    ContourShading->False], _Line, -1]

DisplayFunction->Graphics causes the new contour plot to be converted
straight to Graphics without being displayed, and ContourShading->False
causes the shaded Polygon's to be left out of the Graphics object,
since they are baggage unimportant to calculating the contour lines.  If
you actually do want a new graph displayed for every new contour
computed, use Graphics @ Show[figure, Contours->{z0}] as the first
argument of Cases instead.


  Here is a general function LevelCurve that returns a rule
z -> {Line, ...} for each contour you ask for.

ExtractLines[cgraph_ContourGraphics] :=
  Cases[Show[cgraph, ContourShading->False, DisplayFunction->Graphics],
    _Line, -1]

LevelCurve[cgraph_ContourGraphics, z_List] :=
  (# -> Show[cgraph, Contours->{#}, DisplayFunction->ExtractLines] )& /@ z

LevelCurve[cgraph_ContourGraphics, z_] :=
  First @ LevelCurve[cgraph, {z}]



Example:

In[5]:= cplot = ContourPlot[Arg @ AiryAi[x + y I], {x, 3, 5}, {y, -4, -2},
  PlotPoints->40]

Out[5]= -ContourGraphics-

In[6]:= LevelCurve[cplot, 5/6 Pi]

        5 Pi
Out[6]= ---- ->
         6

>    {Line[{{5., -3.82523}, {4.94872, -3.84198}, {4.93604, -3.84615},

>       {4.89744, -3.85893}, {4.84615, -3.87607}, {4.79487, -3.89341},

>       {4.78304, -3.89744}, {4.74359, -3.91095}, {4.69231, -3.92869},

>       {4.64103, -3.94665}, {4.63515, -3.94872}, {4.58974, -3.96481},

>       {4.53846, -3.98319}, {4.49209, -4.}}]}


Robby Villegas


  • Prev by Date: Re: Help on FindRoot
  • Next by Date: Re: grid plot
  • Previous by thread: Contour Plot
  • Next by thread: Help me please!!!