I have a function f
which takes a number as input, and returns a list of numbers (the length of the list is constant). f
is hard to calculate (each evaluation takes a long time).
I want to plot the different components of f
in different colors.
If I use this command:
Plot[f[x], {x, -2, 2}]
all the lines are drawn in the same color.
If I use this command:
Plot[{f[x][[1]], f[x][[2]], f[x][[3]]}, {x, -2, 2}]
(assuming the list has three components) the lines are drawn in different colors, but the function is called three times the necessary amount.
Note that this is a numeric function, it cannot be evaluated with a symbolic argument (i.e. the function definition begins with f[x_Real]:=
), so there is no use in using Evaluate
like in this question.
Plot[f[t],...]
evaluatesf
multiple times.f[x_Real] := (i++; {x, x + 1, x + 2})
andi = 0; Plot[f[t], {t, 0, 1}, PlotPoints -> 10, MaxRecursion -> 0]
, thenPrint[i]
. The result is 31, not 10-ish. So, solutions just usingPlot
may not work as well. $\endgroup$