Re: extracting points plotted by ContourPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg3396] Re: [mg3356] extracting points plotted by ContourPlot
- From: penny at edu-suu-scf.sc.suu.edu (Des Penny)
- Date: Sun, 3 Mar 1996 02:25:38 -0500
- Sender: owner-wri-mathgroup at wolfram.com
>Hi! > >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! > >Richard ************************************************************************* 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: Show[Graphics[contourLine]]; We can now abstract the desired xydata of the curve f[x,y]=0: xyData=contourLine[[1,3,1]]; We can now manipulate this xyData as desired. We can plot it again if needed: ListPlot[xyData]; Hope this helps, Cheers, 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 suu.edu ========================== ==== [MESSAGE SEPARATOR] ====