Message Boards Message Boards


[✓] Extract raw data (list of points for each line) from ListContourPlot?

Posted 1 year ago
4 Replies
1 Total Likes

I was wondering if it is possible to extract the raw data (the x and y coordinates of the points used to draw the contour lines) from ListContourPlot. I would like to do further analysis on the shapes of certain contour lines, and having the raw data would be extremely useful. Any suggestions?

4 Replies

Hi Matty,

you can "explore" every object in WL using the command FullForm. Then you can see how details can be extracted. In the case of contour lines one can try this:

(* example plot using "ContourShading\[Rule]None": *)    
data = RandomReal[1, {10, 10}];
plot = ListContourPlot[data, InterpolationOrder -> 3, PlotRange -> All, ContourShading -> None]

You get a list of lines (according to the levels) like so:

lines = Normal[First@plot][[2]];

To convince yourself on what you get try:

plotRange = First@AbsoluteOptions[plot, PlotRange];
Manipulate[Graphics[lines[[;;n]], plotRange], {n, 1, Length[lines], 1}]

enter image description here

Hope that helps, regards -- Henrik


[source code] /. conts -> plot

Henrik, that is very helpful. I think that I have seen FullForm before but I didn't know that it did that, exactly. That's awesome!

I appreciate the example, but did "conts" get defined in the code that you provided. I hope that I'm not being dense, but I couldn't get your example to run (except for the first part where you generated the initial data set and contour lines). If something got left out, I'd love to see it, if you wouldn't mind sending it along.

Thanks again for the help. Much appreciated.

Take care,


Ah, awkward! conts should read plot - sorry! I already edited my post above, now it should run.

And here comes another little restriction on what I have stated: The method above works only as long as the objects are not atomic. So in our case we are lucky:

(* Out:   False *)

A counterexample would e.g. be some mesh object:

mesh = DelaunayMesh[RandomReal[1, {50, 3}]]

Thank you so much. That clears things up perfectly. I really appreciate the help.


Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract