Given a ContourPlot
with a set of contours, say, this:
is it possible to get the contours separating domains with the different colors in the form of lists?
For example, how to extract the boundaries of the blue domain in the image above? Or just for the sake of trial, from such a simple example:
ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 3}, {y, -3, 3},
PlotRange -> {0, 0.5}, ColorFunction -> "Rainbow"]
The same task, let us find the lists corresponding to the blue domain boundaries.
To make it clear, I am not asking of how to get the lines from the function behind. This I understand. I ask of how to extract the contour lines that are generated by Mma.
Let us put this question another way around. Is it possible to define the areas with the same color as separate geometric regions in the sense of the computation geometry, and then work with these domains separately?
Answer
To answer the last question, the contour domains (since V8) are enclosed separately in GraphicsGroup
, each which you can cull and turn into a region:
plot = ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 3}, {y, -3, 3},
PlotRange -> {0, 0.5}, ColorFunction -> "Rainbow"];
regs = With[{coords = First@Cases[plot, GraphicsComplex[p_, ___] :> p, Infinity]},
BoundaryDiscretizeGraphics@
GraphicsComplex[coords, #] & /@ Cases[plot, _GraphicsGroup, Infinity]
];
Multicolumn[regs, 5]
Comments
Post a Comment