1
$\begingroup$

My purpose is to animate a (list) plot by removing points from it (adding ones to it) live. I would like to show how these actions influence my plot and my error (it should also change live as I remove some points). Is it possible in Mathematica? I already know how to show the list flow, but it's not quite what I was looking for. I would be grateful for any help on this.

$\endgroup$
2
  • $\begingroup$ How do you want to add/remove points? Explicitly typing out coordinates? Clicking on the plot itself? $\endgroup$ – J. M.'s ennui Apr 13 '18 at 5:54
  • $\begingroup$ Clicking on the points / plot itself was what I was thinking about. Typing out coordinates would do as well, though. $\endgroup$ – aniager Apr 13 '18 at 5:55
4
$\begingroup$

As a proof of concept (which you can adjust to your needs), here is a Manipulate[] that demonstrates least-squares fitting of a line to a set of points:

Manipulate[Graphics[{{Directive[AbsoluteThickness[3], ColorData[97, 3]], lsline[pts]},
                     {Directive[AbsolutePointSize[7], ColorData[97, 2]], Point[pts]}},
                    Axes -> True, PlotRange -> 5/2],
           {{pts, RandomReal[{-2, 2}, {2, 2}]}, Locator, 
            Appearance -> None, LocatorAutoCreate -> True}, 
           Initialization :> (lsline[pts_] := InfiniteLine[{0, #1}, {1, #2}] & @@ 
                              LeastSquares[Transpose[PadLeft[{pts[[All, 1]]},
                                                             {2, Automatic}, 1]],
                                           pts[[All, 2]]]), SaveDefinitions -> True]

Manipulate

The most relevant part here is the use of a Locator control within Manipulate[] with the set option LocatorAutoCreate -> True; with this, in addition to being able to drag points around the plot, you can Alt+click on points to remove them, or Alt+click on a blank area to add points.

$\endgroup$
1
  • $\begingroup$ Thank you so much!!! $\endgroup$ – aniager Apr 13 '18 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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