8
$\begingroup$

I need to change color to selected points dynamically in my plot.

clicks = {}; insert = 0;
Column[{
   ListPlot[Button[Tooltip@#, If[insert < 5 && ! MemberQ[clicks, #],
      AppendTo[clicks, #]; insert++;]] & /@ N@data, ImageSize -> 300], "\n\t",
    Row[{"clicks = ", Dynamic[clicks // TableForm]}],   
    Row[{Button["Del L1", If[Length[clicks] >= 1, insert--; clicks = Delete[clicks, 1]]]}]}
]

plot

I managed how to get x/y clicked, but not how to highlight it.

$\endgroup$
0
9
$\begingroup$
clicks = {}; insert = 0;
data = RandomReal[100, {50, 2}];

You can add the points in clicks using Epilog:

Column[{ListPlot[Button[Tooltip@#, 
        If[insert < 5 && ! MemberQ[clicks, #], AppendTo[clicks, #]; 
         insert++;]] & /@ N@data, ImageSize -> 400, 
   Epilog -> Dynamic[{ Directive[Opacity[.7, Red], PointSize[Large]], Point@clicks}]], 
   "\n\t",  Row[{"clicks = ", Dynamic[clicks // TableForm]}], 
   Row[{Button["Del L1", If[Length[clicks] >= 1, insert--; 
      clicks = Delete[clicks, 1]]]}]}]

enter image description here

Alternatively, you can Style the points in clicks and add them to the list of points to be plotted:

Dynamic@Column[{ListPlot[Join @@ 
   {Style[#, Directive[Opacity[.5], Orange, Magnification -> 2]] & /@ clicks, 
    Button[Tooltip[#], If[insert < 5 && ! MemberQ[clicks, #], AppendTo[clicks, #]; 
            insert++;]] & /@ N@data}, ImageSize -> 400, 
    BaseStyle -> PointSize[Large]], "\n\t", 
   Row[{"clicks = ", Dynamic[clicks // TableForm]}], 
   Row[{Button["Del L1", If[Length[clicks] >= 1, insert--; 
       clicks = Delete[clicks, 1]]]}]}]

enter image description here

$\endgroup$

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.