2
$\begingroup$

This question already has an answer here:

I have a ListContourPlot, and I'm interested in extracting the data of one of the contours. Here is an example and I highlighted the contour that I would like to extract the data from:

ListContourPlot[Table[{i, Sin[i] // N}, {i, 0, 10}],
 Contours -> {2 - 0.1, 2 + 0.1},
 ContourStyle -> Black,
 ContourShading -> {White, Black}]

Is there a way to do this, beside manually reading the data?

$\endgroup$

marked as duplicate by Jason B., m_goldberg, user9660, RunnyKine, MarcoB Apr 14 '16 at 2:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4
$\begingroup$

You can use Cases to extract the Line objects from the contour plot, and then extract the points from those lines.

ListContourPlot[Table[{i, Sin[i] // N}, {i, 0, 10}], 
 Contours -> {2 - 0.1, 2 + 0.1}, ContourStyle -> Black, 
 ContourShading -> {White, Black}]

enter image description here

Cases[Normal@%, Line[pts__] -> pts, Infinity]

(* {{{1., 3.1}, {1.31481, 4.}, {1.23957, 4.23957}, {1.39943, 
   5.}, {1.38315, 5.38315}, {1.48667, 6.}, {1.5493, 6.5493}, {1.62108,
    7.}, {1.72993, 7.72993}, {1.7725, 8.}, {1.81522, 
   8.81522}, {1.84158, 9.}, {1.77756, 9.77756}, {1.80346, 
   10.}, {1.72297, 10.723}, {1.74924, 11.}}, {{1., 2.9}, {1.09168, 
   3.}, {1.0538, 3.0538}, {1.38477, 4.}, {1.2928, 4.2928}, {1.44147, 
   5.}, {1.42348, 5.42348}, {1.52023, 6.}, {1.58719, 
   6.58719}, {1.65293, 7.}, {1.76736, 7.76736}, {1.80403, 
   8.}, {1.8485, 8.8485}, {1.87011, 9.}, {1.80391, 9.80391}, {1.82675,
    10.}, {1.74392, 10.7439}, {1.76821, 11.}}} *)

This is the data, now plot it with

ListLinePlot@%

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.