Update: If we extract Polygon
s (instead of FilledCurve
s) we can use many Mesh*
and Region*
functions on the extracted polygons:
SeedRandom[1];
cp = ContourPlot[Evaluate[Sum[Sin[RandomReal[5, 2] . {x, 5 y}], {10}]],
{x, 0, 5}, {y, 0, 5}, Contours -> 20, ContourShading -> None];
polygons = Cases[Normal@cp,
Line[x_] /; x[[{1, -1}, 1]] == {0., 0.} || x[[{1, -1}, 1]] == {5., 5.} :>
Polygon @ x, All];
Graphics[{RandomColor[], #} & /@ polygons]
largest20 = TakeLargestBy[polygons, Area, 20];
Graphics[{RandomColor[], #} & /@ largest20]
Multicolumn[DiscretizeRegion /@ largest20, 5]
Original answer:
Contour lines of a surface do not intersect.
So, we can take contour lines of a random surface and select the lines that start and end on the left or the right end of the horizontal range:
SeedRandom[1];
cp = ContourPlot[Evaluate[Sum[Sin[RandomReal[5, 2] . {x, 5 y}], {10}]],
{x, 0, 5}, {y, 0, 5}, Contours -> 20, ContourShading -> None];
Graphics @ Cases[Normal @ cp,
l : Line[x_] /; x[[{1, -1}, 1]] == {0., 0.} || x[[{1, -1}, 1]] == {5., 5.} :>
{RandomColor[], FilledCurve@l}, All]
We can also use ListContourPlot
:
SeedRandom[1];
lcp = ListContourPlot[RandomReal[{-.25, .25}, {20, 15}],
InterpolationOrder -> 3, Contours -> 20, ContourShading -> None];
Graphics @ Cases[Normal@lcp,
l : Line[x_] /;
x[[{1, -1}, 1]] == {1., 1.} || x[[{1, -1}, 1]] == {15., 15.} :>
{l, RandomColor[], FilledCurve @ l}, All]