2
$\begingroup$

How can Plotlegend label each curve with the corresponding value of parameter param in the code below?

  s = ParametricNDSolve[{x'[t] == y[t], y'[t] == x[t], x[0] == param, 
    y[0] == param}, {x, y}, {t, 0, 1}, {param}, 
   WorkingPrecision -> 70, PrecisionGoal -> 20];
Plot[Evaluate[Table[x[param][t] /. s, {param, 1, 10}]], {t, 0, 1}, 
 PlotLegends -> Automatic]
$\endgroup$
  • 1
    $\begingroup$ If you want to use PlotLegends use Plot[Evaluate[Table[x[param][t] /. s, {param, 10, 1, -1}]], {t, 0, 1}, PlotLegends -> Range[10, 1, -1]] $\endgroup$ – Bob Hanlon May 23 at 13:46
3
$\begingroup$

You can use the option PlotLabels:

Plot[Evaluate[Table[x[param][t] /. s, {param, 1, 10}]], {t, 0, 1},
   PlotLabels -> Range[10]]

enter image description here

Alternatively, you can use Callout wrapper on each table element:

Plot[Evaluate[Table[Callout[x[param][t] /. s, param], {param, 1, 10}]], {t, 0, 1}]

same picture

You can also use Labeled as follows:

Plot[Evaluate[Table[Labeled[x[param][t] /. s,param], {param, 1, 10}]], {t, 0, 1}]

enter image description here

Or add the labels using Epilog:

Plot[Evaluate[ Table[x[param][t] /. s, {param, 1, 10}]], {t, 0, 1}, 
 Epilog -> MapIndexed[Text[#2[[1]], Offset[{10, 0}, {1, #}]] &, 
   Table[x[param][1] /. s, {param, 1, 10}]], 
 PlotRangeClipping -> False, ImagePadding -> Scaled[.05]]

almost same picture

$\endgroup$
  • $\begingroup$ Unfortunately in Mathematica 10.0 I get a Plot::optx: Unknown option PlotLabels->{1,2,3,4,5,6,7,8,9,10} in <<1>>. >> error (PlotLabels in red). $\endgroup$ – student May 24 at 6:39
  • $\begingroup$ @student, PlotLabels should work in versions 10.4 and later. Does Labeled work in your version? $\endgroup$ – kglr May 24 at 7:34
  • $\begingroup$ @student, Epilog method should work in versions 9+. $\endgroup$ – kglr May 24 at 7:42

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.