2
$\begingroup$

I have a list of functions, the length of the list is not sure. Maybe be just like:

f = {x, x^2, x^3, x^4};
Plot[f, {x, 0, 2}, PlotLabels -> {"1","2","3","4"}]

I want they are labeled by the function number, when I know the total number, I will give labels by hand (I think not good way), but if I don't know the total number, how to automatic show labels?

$\endgroup$
0
3
$\begingroup$
ClearAll[f]
f = {x, x^2, x^3, x^4};


Plot[f, {x, 0, 2}, PlotLabels -> Range[Length@f]] (* or *)

Plot[Evaluate@MapIndexed[Callout[#, #2[[1]]] &, f], {x, 0, 2}] (* or *)

Plot[Evaluate@MapIndexed[Labeled[#, #2[[1]]] &, f], {x, 0, 2}] (* or *)

all give

enter image description here

$\endgroup$
1
  • $\begingroup$ Or adding Tooltip: Plot[f, {x, 0, 2}, PlotLabels -> (Tooltip[#, f[[#]]] & /@ Range@Length@f)] $\endgroup$ – Bob Hanlon Feb 17 '20 at 18:58

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.