3
$\begingroup$

I have the following list:

l={{1,2},{3,4},{5,6}}

I want to list plot above such that the first element {1,2} can be labeled "a", {3,4} labeled "b" and {5,6} to be labeled "c", I know I can label coordinates using,

ListPlot[Labeled[#, #] & /@ l]

for which I get,

enter image description here

But I want the label to be "a", "b" and "c"

$\endgroup$
6
  • 2
    $\begingroup$ l = {{1, 2}, {3, 4}, {5, 6}}; labels = {"a", "b", "c"}; ListPlot[Labeled[l[[#]], labels[[#]]] & /@ Range[Length[l]]]. $\endgroup$
    – JimB
    Aug 1, 2018 at 16:01
  • $\begingroup$ Thanks, if you post this as answer I can accept it :) $\endgroup$
    – Wiliam
    Aug 1, 2018 at 16:04
  • 1
    $\begingroup$ From the docs: ListPlot[{{1, 2}, {3, 4}, {5, 6}} -> {"a", "b", "c"}, LabelingFunction -> Above] $\endgroup$
    – user1066
    Aug 1, 2018 at 16:04
  • $\begingroup$ LabelingFunction doesn't work for me $\endgroup$
    – Wiliam
    Aug 1, 2018 at 16:06
  • $\begingroup$ @user1066 has a better (simpler and direct) answer so that's the one you should select. But your comment suggests you might have an older version of Mathematica. It works fine on 11.3 Windows 10. You should mention in your question which Mathematica version and operating system you have. $\endgroup$
    – JimB
    Aug 1, 2018 at 16:06

2 Answers 2

1
$\begingroup$
list = {{1, 2}, {3, 4}, {5, 6}}; labels = {"a", "b", "c"};

ListPlot @ Thread @ Labeled[list, labels, Above]

enter image description here

$\endgroup$
1
$\begingroup$
list = {{1, 2}, {3, 4}, {5, 6}};

labels = {"a", "b", "c"};

ListPlot labels associations automatically

ListPlot @ AssociationThread[labels -> list]

enter image description here

$\endgroup$

Your Answer

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

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