4
$\begingroup$

When I use ListPlot, I want to show the labels, such as

ListPlot[Callout[#, #, Above] & /@ Range[10], Joined -> True, Mesh -> All]

Now all positions are Above, but sometimes the labels will over other text, so I want to set some of them Below, for example, the second and third point labels are Below, as the image shows.

enter image description here

$\endgroup$

2 Answers 2

7
$\begingroup$
ListPlot[Callout[#, #, # /. {2 | 3 | 8 -> Below, _ -> Above}] & /@ Range[10], 
  Joined -> True, Mesh -> All]

enter image description here

$\endgroup$
0
$\begingroup$

One way is use MapAt

data = Range[10];
mapBelow[n_] := MapAt[Callout[#, #, Below] &, n];
mapAbove[n_] := MapAt[Callout[#, #, Above] &, n];
below = Table[mapBelow[n], {n, {2, 3, 8}}];
above = Table[mapAbove[n], {n, Complement[Range[10], {2, 3, 8}]}];
ListPlot[Composition[Sequence @@ Flatten[{above, below}]][data], 
 Joined -> True, Mesh -> All]

enter image description here

$\endgroup$

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.