3
$\begingroup$

If I make a simple plot with points I want to label using Callout this fails. For example:

dataWithCallouts={Callout[{0.6, 0.9}, 1], Callout[{0.850558, 0.895379}, 2], 
 Callout[{-0.146155, -0.258084}, 3], Callout[{0.818206, 0.672661}, 4],
  Callout[{0.943998, 0.794068}, 5], Callout[{0.191938, 0.404059}, 6], 
 Callout[{0.598051, 0.614664}, 7], Callout[{0.6, 0.9}, 8], 
 Callout[{0.850558, 0.895379}, 9], 
 Callout[{-0.146155, -0.258084}, 10], 
 Callout[{0.818206, 0.672661}, 11], Callout[{0.943998, 0.794068}, 12],
  Callout[{0.191938, 0.404059}, 13]};
ListPlot[dataWithCallouts]

Only shows the label for point 7 and not for any of the other points. What is going wrong here?

$\endgroup$

1 Answer 1

6
$\begingroup$

All points but number seven appear twice, so ListPlot does not know how to label them. If you remove the duplicates, every point gets a label.

ListPlot@DeleteDuplicatesBy[dataWithCallouts, First]

enter image description here

You could combine the duplicate labels like this (adapting Roman's answer here)

Callout @@@ KeyValueMap[List, GroupBy[dataWithCallouts, First -> Last]] // ListPlot

enter image description here

$\endgroup$
2
  • $\begingroup$ Wow thank you, that was so stupid of me not to notice. $\endgroup$
    – Kvothe
    Jan 25, 2021 at 14:13
  • $\begingroup$ Thanks a lot! I guess I should delete my question because "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." Although perhaps it would help to leave it up for someone who makes the same mistake. Actually with your edit I do think there is added value in this answer since it shows how to combine labels if there are duplicates. So I will leave it to the moderators whether this question can stay. $\endgroup$
    – Kvothe
    Jan 25, 2021 at 14:17

Your Answer

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

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