Is there a cleaner way to apply different styles to the different channels of a multi value interpolation function?
here is a 2-output interpolation function:
f = Interpolation[Table[ {x, N@{Sin[x], Cos[x]}}, {x, 0, 2 Pi, Pi/20}]]
if we just plot it the two functions take the same style
Plot[f[x], {x, 0, 2 Pi}, PlotStyle -> {Red, Blue}]
Here is one way to separately style:
Plot[{f[x][[1]], f[x][[2]]}, {x, 0, 2 Pi}, PlotStyle -> {Red, Green}]
This feels inefficient, apparently this computes both interpolations twice. I also cant figure an incantation to do this without explicitly listing..
Plot[Table[f[x][[i]], {i, 2}], {x, 0, 2 Pi}]
doesn't work.
We can crunch out a table and use ListPlot
, but that seems unsatisfactory.
Is there a cleaner way?
Plot
seesf[x]
as a single object and therefore only recognizes onePlotStyle
whereasPlot
sees{f[x][[1]],f[x][[2]]}
as two objects (as you've discovered). I wish I could remember but it wasn't that long ago and it had a good explanation of the issue. $\endgroup$styleSplitter
works as it stands. $\endgroup$