1
$\begingroup$

When it comes to labelling every single point on a ListPlot there might be some labels overlapping. Thus, I would like to manually position the labels with a Line linking them to their associated point.

The following shows the idea:

coord={{0,0},{1,1}};
Manipulate[
  Show[
   Graphics[{Red,Line[{#2,1.02*#}]&@@@Thread[{pt,coord}]}],
   ListPlot[{coord}],ImageSize->250],    
{{pt,coord},Locator,Appearance->(#&/@{"a","b"})}]

Mathematica graphics

When it comes to more than one dataset I'm having an issue.

coord = {{0, 0}, {1, 1}};
coord1 = {{-1, 1}, {2, 0}};
Manipulate[
  Show[
    Graphics[{Red, Line[{#2, 1.02*#}] & @@@ Thread[{pt, coord}], 
              Blue, Line[{#2, 1.02*#}] & @@@ Thread[{pt1, coord1}]}], 
    ListPlot[{coord, coord1}]],
  {{pt, coord}, Locator, Appearance -> (# & /@ {"a", "b"})},
  {{pt1, coord1}, Locator, Appearance -> (# & /@ {"c", "d"})}]
$\endgroup$
3
$\begingroup$

From Introduction To Manipulate

Due to internal limitations, it is not possible to combine individual Locator variables with a variable that is a list of multiple Locator variables: you can have only one multipoint Locator variable in a Manipulate. ...

A work-around:

coord = {{0, 0}, {1, 1}};
coord1 = {{-1, 1}, {2, 0}};
coords = Join[coord, coord1];

Manipulate[Show[Graphics[{Red, Line[{#2, 1.02*#}] & @@@ Thread[{pts[[;; 2]], coord}], 
                          Blue,Line[{#2, 1.02*#}] & @@@ Thread[{pts[[3 ;;]], coord1}]}], 
                ListPlot[{coord, coord1}]], 
          {{pts, coords}, Locator, Appearance -> (# & /@ {"a", "b", "c", "d"})}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ Ah, I guess there is no other way when using Manipulate then, thanks for the explanation. $\endgroup$ – Öskå Jun 6 '14 at 16:09
  • $\begingroup$ The construct (# & /@ {"a", "b", "c", "d"}) can be simplified to just {"a", "b", "c", "d"} $\endgroup$ – Bob Hanlon Jun 6 '14 at 16:26
  • $\begingroup$ @BobHanlon In that simple case indeed :) $\endgroup$ – Öskå Jun 6 '14 at 16:27
  • 1
    $\begingroup$ @Öskå, If you do not need all this inside Manipulate for other reasons, you might consider using Locator as a graphics primitive as in ListPlot[Sort@RandomInteger[10, {20, 2}], Joined -> True, Mesh -> All] /. Point[x_] :> Locator /@ x.. $\endgroup$ – kglr Jun 6 '14 at 16:57
  • $\begingroup$ @kguler I don't need the Manipulate indeed. I'm currently facing the fact that Locators disappear when being exported, with that method they are exported. So that might be the key :) One problem remains, I have right now no clue how to adapt your comment to the example in the question.. :) $\endgroup$ – Öskå Jun 6 '14 at 17:00

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.