Re: Exporting ContourPlot data into text file to plot somewhere else..
- To: mathgroup at smc.vnet.net
- Subject: [mg91358] Re: Exporting ContourPlot data into text file to plot somewhere else..
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sun, 17 Aug 2008 06:41:45 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <g86832$hq8$1@smc.vnet.net>
malawk at gmail.com wrote: > How can I export ContourPlot data to a text file? > > I read some instructions in this forum to do this for normal plots: > > e.g.: > > plt = Plot[Sin[x], {x, 0, 5}] > First[Cases[plt, _Line, Infinity] /. Line[pnts_] :> pnts] > > which return a neat list of pairs of numbers to plot somewhere else. > With ContourPlot though, this command returns only one column of > numbers in sequencial order... Not good...! Different kind of plots have different internal structures. Fortunately, since in Mathematica everything is an expression, plots can be manipulated as any other expression. Therefore, FullForm[] will reveal internal structure (in Mathematica language) of the expression that represents a given plot and Part[], provided withe the correct indices, will extract any parts of the plot as it would do for any other expression. (Of course, other method are applicable, such as replacement rules, which does not mean that a given replacement rule will work on every plots.) For instance, cp = ContourPlot[Cos[x] + Cos[y] == 1/2, {x, 0, 4 Pi}, {y, 0, 4 Pi}] FullForm[cp] (* To see the internal structure of the plot. *) cp[[1, 1]] (* To extract only the relevant structure of the plot*) Regards, -- Jean-Marc