5
$\begingroup$

I recently had my interest peaked by the excellent thread "Exclude data from a list." In particular, the second answer which constructs an interactive eraser which allows one to delete data points in a ListPlot. For example,

data = Table[{RandomReal[{-10, 10}], RandomReal[{-10, 10}]}, {i, 1, 300}];
DynamicModule[{pt = {0, 0}, r = 3}, 
   Column[{Slider[Dynamic[r], {0.1, 5}], 
   Button["Delete", 
     data = Select[data, EuclideanDistance[#, pt] > r &]], 
   LocatorPane[Dynamic[pt], 
     Dynamic[
       ListPlot[data, 
         Frame -> True, 
         Axes -> False, 
         AspectRatio -> 1, 
         Epilog -> Circle[pt, r],
         ImageSize -> 300]],
      Appearance -> None]}]]

My question is, can one do something like this with ContourPlot? My idea was to make a contour plot, and then use Union to extract the data points, and plot them with ListPlot to apply the eraser:

F[x_, y_] := x^2 + y^2 - 4;

AB = Union[ContourPlot[{F[x, y] == 0}, {x, -3, 3}, {y, -3, 3}][[1, 1]]];
DynamicModule[{pt = {0, 0}, r = 3}, 
  Column[
    {Slider[Dynamic[r], {0.1, 5}], 
     Button["Delete", AB = Select[AB, EuclideanDistance[#, pt] > r &]], 
     LocatorPane[Dynamic[pt], 
       Dynamic[ListPlot[AB, 
         Frame -> True, 
         Axes -> False, 
         AspectRatio -> 1, 
         Epilog -> Circle[pt, r], 
         ImageSize -> 300]], 
       Appearance -> None]}]]

The problem with this attempt is that there's many gaps in the ListPlot. So does anyone know how to improve my awful method? Or perhaps is there another way to erase certain data points from a ContourPlot? If it helps, I don't care about collecting the resulting data points at all; this is purely about plotting a result.

$\endgroup$
3
  • 2
    $\begingroup$ If F is really the input then taking about erasing points doesn't make sense so much. ContourPlot[{F[x, y] == 0}, {x, -3, 3}, {y, -3, 3}, RegionFunction -> Function[{x, y}, EuclideanDistance[{x, y}, {2, 0}] > 1]] is something to start with, you can also take a look at ImplicitRegion, RegionDifference and friends. $\endgroup$
    – Kuba
    Commented Aug 12, 2016 at 19:27
  • $\begingroup$ @Kuba Why exactly doesn't it make much sense? Maybe I should have said I was hoping to erase certain points in the zero set I told ContourPlot to plot. $\endgroup$
    – Benighted
    Commented Aug 12, 2016 at 20:13
  • 2
    $\begingroup$ Because F[x, y] == 0 represents an infinite set of points and using Select approach with sample point representation you will lose precission quite quickly, as you noticed. $\endgroup$
    – Kuba
    Commented Aug 12, 2016 at 20:21

1 Answer 1

6
$\begingroup$

Maybe an implementation using ListCurvePathPlot will work for you. With your example contour function it works well. It might not work so well for less well-behaved contours.

F[x_, y_] := x^2 + y^2 - 4
contour = 
  Union[ContourPlot[{F[x, y] == 0}, {x, -3, 3}, {y, -3, 3}][[1, 1]]];

DynamicModule[{pts = contour, eraser = {0, 0}, eraserR = .2},
 Column[
   {Row[
      {Style["eraser radius ", "SR"], 
       Slider[Dynamic[eraserR], {.05, 1., .05}], " ",
       Dynamic[eraserR]}], 
    Button["Delete", 
      pts = Select[pts, EuclideanDistance[#, eraser] > eraserR &]],
    LocatorPane[Dynamic[eraser],
      Dynamic[ListCurvePathPlot[pts,
        Frame -> True,
        Axes -> False,
        PlotRange -> {{-2, 2}, {-2, 2}},
        PlotRangePadding -> Scaled[.05],
        Epilog -> Circle[eraser, eraserR],
        ImageSize -> 350]],
      Appearance -> None]}]]

Here is how it looks at start-up.

initial

And this is how it looks after some deletions.

modified

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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