1
$\begingroup$

I have the following:

data = {{643.5, 780.5}, {659.5, 780.5}, {627.5, 761.5}, {643.5, 761.5}, {659.5, 761.5}, {627.5, 742.5}, {643.5, 742.5}, {659.5, 742.5}, {627.5, 723.5}, {643.5, 723.5}}

where its plot is:

ListPlot[data, PlotStyle -> Black]

enter image description here

From the plot, I want to choose, let's say, three points, and cut and paste them in order to make a new list. For this, I click on the plot and choose one point where its color becomes orange. My question is: 1. How can I choose three points at once? and 2. How can I cut and paste their coordinates into a new list, instead of reading them from the dataset in the above?

$\endgroup$
2
  • 1
    $\begingroup$ See Get Coordinates From Graphics However, if you can specify some criteria it would be easier and more accurate to use Select or Cases or ... $\endgroup$
    – Bob Hanlon
    Nov 21, 2022 at 13:45
  • $\begingroup$ " how can I realize to which point in my dataset corresponds" -> Do you mean the position of the point in the dataset ? like first, 2nd, 12th etc ? $\endgroup$ Nov 21, 2022 at 17:44

2 Answers 2

3
$\begingroup$
data = {{643.5, 780.5}, {659.5, 780.5}, {627.5, 761.5}, {643.5, 
     761.5}, {659.5, 761.5}, {627.5, 742.5}, {643.5, 742.5}, {659.5, 
     742.5}, {627.5, 723.5}, {643.5, 723.5}} // Sort;

Using Manipulate with a TogglerBar

Manipulate[
 Grid[
  {{ListPlot[
     ({remaining, choosen} =
        {Complement[data, selected],
         selected}) /.
      {} :> Nothing,
     PlotRange -> All,
     PlotMarkers -> {If[remaining === {},
        Style["■", Orange, 16],
        Style["●", Blue]],
       Style["■", Orange, 16]}],
    SpanFromLeft},
   {"remaining", "choosen"},
   {remaining, choosen}},
  Frame -> All],
 {{selected, {}},
  Thread[data -> Range[Length@data]],
  ControlType -> TogglerBar}]

enter image description here

EDIT: Added Tooltip and better formatting.

Manipulate[
 Grid[{{
    ListPlot[
     ({remaining, choosen} = Sort /@ {
          Complement[data, selected], selected}) /.
      {{} :> Nothing,
       x : {_?NumericQ, _?NumericQ} :>
        Tooltip[x, Style[Position[data, x][[1, 1]], 20]]},
     PlotRange -> All,
     PlotRangePadding -> Scaled[.05],
     ImagePadding -> 20,
     PlotMarkers -> {
       If[remaining === {},
        Style["■", Orange, 16], 
        Style["●", Blue]],
       Style["■", Orange, 16]}],
    SpanFromLeft},
   {"remaining", "choosen"},
   Column /@ {remaining, choosen}},
  Frame -> All,
  ItemSize -> 12],
 {{selected, {}},
  Thread[data -> Range[Length@data]],
  ControlType -> TogglerBar}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Very neat ! I added it to my personal list of neat functions for future use. $\endgroup$ Nov 22, 2022 at 10:24
1
$\begingroup$

Right click on the graphics and choose "Get Coordinates". A crosshair cursor appears. Click on the first point. Now a palette with drawing tools appears and the crosshair cursor disappears:

enter image description here

Right click again on the graphics and choose again "Get Coordinates". The crosshair corsair appears again. Then click the other points you want to get the coordinates. Finally hit "Ctrl C" to get the coordinates into the clipboard. Now, you can paste the coordinates wherever you like by "Ctrl V".

Note that this is valid for MMA version 13.1 Windows 10. How it works in other versions, I do not know.

$\endgroup$
0

Your Answer

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