2
$\begingroup$

Function of interest:

f[n_, r_] := (1 - r^2)^((n - 4)/2)/(Beta[1/2, (n - 2)/2])

In separate graphs:

Table[  Plot[f[n, r], {r, -1, 1},   Frame -> True,   GridLines -> Automatic,   PlotLegends -> "Expressions"   ], {n, 4, 19}]

Now if I do

Plot[Table[f[n, r], {n, 4, 19}], {r, -1, 1},  Frame -> True,  PlotLegends -> "Expressions"  ]

enter image description here

This gives no Legends. Then I try

tmp = Table[f[n, r], {n, 4, 19}]
Plot[tmp, {r, -1, 1},  Frame -> True,  PlotLegends -> "Expressions"  ]

enter image description here It works fine, but not exactly the legends I want. How can I have legends with specific values of n and r, like f(8,r), or f(4,r), or anything that is more informative?

Plot[tmp, {r, -1, 1},  Frame -> True,  PlotLegends -> Table["f(" <> ToString[n] <> ",r)", {n, 4, 19}]  ]

enter image description here

This is also ok, but is can I do it without introducing the exatra tmp variable? There must be a more efficient way.

Thanks.

$\endgroup$
0

1 Answer 1

4
$\begingroup$
Plot[Evaluate @ Table[f[n, r], {n, 4, 19}], {r, -1, 1}, Frame -> True, 
 PlotLegends -> Table["f(" <> ToString[n] <> ",r)", {n, 4, 19}]]

enter image description here

You can also use

 PlotLegends -> Table[Inactivate @ f[n, r], {n, 4, 19}] (* or *)
 PlotLegends -> (TraditionalForm @ Defer@f[#, r] & /@ Range[4, 19])

to get the same result.

$\endgroup$

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