1
$\begingroup$

Suppose I have a vector-valued function $f(x)$, and want to plot each component with respect to $x$.

If I try, as stated in the documentation,

Foo[inp_] := {Sin[inp], Cos[inp], Tan[inp]}
Plot[Foo[n], {n, 0, Pi/2}, PlotLegends -> Automatic]

I get a single-coloured plot without any legend. How can I add a legend saying which curve is which component? (I have tried PlotLegends-> "Expressions", which also didn't work)

The output currently looks like this: Output of command

$\endgroup$

1 Answer 1

4
$\begingroup$

You need to wrap Foo[n] in Evaluate:

Foo[inp_] := {Sin[inp], Cos[inp], Tan[inp]};
Plot[Evaluate@Foo[n], {n, 0, Pi/2}, PlotLegends -> "Expressions"]

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.