MathGroup Archive 1996

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

Search the Archive

Re: extracting points plotted by ContourPlot

  • Subject: [mg3396] Re: [mg3356] extracting points plotted by ContourPlot
  • From: penny at (Des Penny)
  • Date: 3 Mar 1996 13:00:45 -0600
  • Approved:
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: Wolfram Research, Inc.
  • Sender: daemon at

>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)?
>If so I would be very grateful!

Hi Richard:

A good reference for graphics questions is "Mathematica Graphics" by Tom
Wickham-Jones.  Pages 632-643 discuss ContourPlot.

The contour plot function generates a rectangular array of heights.
Consider for example:

f[x_,y_] := y-x^2

contour =  ContourPlot[f[x,y], {x,0,2},{y,0,4}, Contours->{0},
        PlotPoints->5, ContourShading->False];

MatrixForm[ contour[[1]] ]

This gives the rectangular array from which a surface can be drawn as follows:

ListPlot3D[ contour[[1]] ]

The ContourPlot function draws the contours as explained on P633 of
"Mathematica Graphics".

In order to abstract the xy data of the curve f[x,y]=0, we proceed as
follows.  We first convert the ContourGraphics object to a Graphics object
and take the first part of it:

contour=ContourPlot[f[x,y], {x,-2,2},{y,0,4}, PlotPoints->30,
                                ContourShading->False, Contours->{0}];

contourLine=First[ Graphics[contour] ];

If you look at the contents of contourLine, you will see it has Line
primitives that can be plotted by:


We can now abstract the desired xydata of the curve f[x,y]=0:


We can now manipulate this xyData as desired.  We can plot it again if needed:


Hope this helps,


Des Penny

Des Penny
Physical Science Dept.
Southern Utah University
Cedar City, UT 84720

VOICE: (Office): (801) 586-7708
       (Home)  : (801) 586-2286
FAX:    (801) 865-8051
e-mail: penny at

  • Prev by Date: Re: extracting points plotted by ContourPlot
  • Next by Date: Mathematica on Solaris x86?
  • Previous by thread: Re: extracting points plotted by ContourPlot
  • Next by thread: Re: extracting points plotted by ContourPlot