Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:


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}};
    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"})}]

1 Answer 1

up vote 3 down vote accepted

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"})}]
Ah, I guess there is no other way when using Manipulate then, thanks for the explanation. –  Öskå Jun 6 at 16:09
The construct (# & /@ {"a", "b", "c", "d"}) can be simplified to just {"a", "b", "c", "d"} –  Bob Hanlon Jun 6 at 16:26
@BobHanlon In that simple case indeed :) –  Öskå Jun 6 at 16:27
@Ö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.. –  kguler Jun 6 at 16:57
@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.. :) –  Öskå Jun 6 at 17:00

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .