# Collecting points in a density plot

I have the following density plot:

DensityPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1} , MeshFunctions -> {#3 &}, Mesh -> 1]


I want to collect the points on the level curve z=1 shown by the mesh on the graph.

• If g is your plot you could just use the output as in ListPlot[Select[g[[1, 1]], 0.99 <= [[1]]^2 + #[[2]]^2 <= 1.01 &]]. Commented Mar 6, 2016 at 9:39
• Try Cases[Normal[(* plot *)], _Line, Infinity] and report back… Commented Mar 6, 2016 at 9:39
• @b.gatessucks Thank you very much, it works. Commented Mar 6, 2016 at 9:58
• @J.M. This method works too. Thank you very much. Commented Mar 6, 2016 at 9:59

The following is just for the sake of entering an answer to this question that has been otherwise answered in comments.

g = DensityPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1} , MeshFunctions -> {#3 &}, Mesh -> 1]


@J.M. suggested extracting the Line object representing the contour line directly from the plot, which is the more straightforward approach in my opinion:

contour = First@Cases[Normal[g], _Line, Infinity]


{Line[{{0.0714286, -0.997354}, {-2.22045*10^-16, -1.}, [...], {0.0714286, -0.997354}}]}

This returns a Line object, which can be visualized directly using Graphics, or from which coordinates can be extracted.

Graphics[contour]
contour[[1]]


{{0.0714286, -0.997354}, {-2.22045*10^-16, -1.}, [...], {0.0714286, -0.997354}}

Alternatively, @b.gatessucks suggested using a Select statement to extract points that belong to the circle.

Note that a # had gone missing in the comment; I would also suggest adding AspectRatio -> Automatic to the ListPlot to make sure that circles are plotted as such, rather than deformed (AspectRatio otherwise defaults to 1/GoldenRatio for the plotting functions):

ListPlot[
Select[g[[1, 1]], 0.99 <= #[[1]]^2 + #[[2]]^2 <= 1.01 &],
AspectRatio -> Automatic
]