4
$\begingroup$

I have a list of of points, and I want to label them $v_1$, $v_2$ etc. How do I go about that? Everywhere I look it seems I can only label using strings.

So let's say

data={{1,1},{2,2},{3,3}}

how do i lable each of these $v_1$,$v_2$,$v_3$

$\endgroup$

2 Answers 2

7
$\begingroup$

One possible way

data = {{1, 1}, {2, 2}, {3, 3}}
lbl = MapIndexed[Subscript[v, First[#2]] &, data ]
ListLinePlot[data -> lbl, Mesh -> All, MeshStyle -> Red, PlotRange -> {0, 4}]

Mathematica graphics

I had to add PlotRange -> {0, 4} due to clippling of last label:

 ListLinePlot[data -> lbl, Mesh -> All, MeshStyle -> Red]

Mathematica graphics

But I think there might be a better way to handle this label clipping at the end without having to explicitly give PlotRange. Will see if I can find one.

If you want to get a little more fancy, you can do

<< MaTeX`
data = {{1, 1}, {2, 2}, {3, 3}}
lbl = MapIndexed[MaTeX["v_" <> ToString@First[#2], Magnification -> 1.5] &, data]
ListLinePlot[data -> lbl, Mesh -> All, MeshStyle -> Red, 
 PlotRange -> {0, 4}, GridLines -> Automatic, 
 GridLinesStyle -> LightGray]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ That works, thank you! $\endgroup$
    – 2132123
    Mar 18, 2022 at 4:36
7
$\begingroup$

You can use the Callout functionality:

data = {{1, 1}, {2, 2}, {3, 3}}
ListLinePlot[
 Table[
  Callout[data[[i]], Subscript[v, i], Above]
  , {i, Length@data}
  ]
 , Mesh -> All
 , MeshStyle -> Red
 , PlotRange -> {{0.5, 3.5}, {0.0, 3.2}}
 ]

enter image description here


EDIT

The good thing about Callout is the automatic placement of labels in a busy plot. Consider the following example.

data = Sort@RandomReal[{-2, 2}, {10, 2}];
pos = ConstantArray[Automatic, Length@data];
lbls = Subscript[v, #] & /@ Range[1, Length@data];
p1 = ListLinePlot[
  MapThread[Callout, {data, lbls, pos}]
  , GridLines -> Automatic
  , Mesh -> All
  , MeshStyle -> Red
  , AspectRatio -> 1/GoldenRatio
  , PlotRange ->
   CoordinateBounds[data] + {{-0.6, 0.6}, {-0.6, 0.6}}
  ]

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.