Skip to main content
2 of 2
edited tags; edited tags
xzczd
  • 71.5k
  • 10
  • 183
  • 524

Plot with different colors the results of an NDSolve with vector solution

Consider the following toy example:

sol = NDSolve[{ x'[t] == {-1, -2} x[t], x[0] == {2, 2} }, x, {t, 0, 4} ]; Plot[x[t] /. sol, {t, 0, 4}, PlotRange -> All] 

enter image description here

As seen above, both plots are drawn in the same colour.

The usual trick of adding Evaluate does not work here, I guess because x[t] /. sol evaluates to a list with a single element:

enter image description here

and it's the InterpolatingFunction that later evaluates to a list.

Manually specifying the PlotStyle also doesn't seem to work.

How can I ensure that the different plots are assigned different colours/styles?

glS
  • 7.8k
  • 1
  • 26
  • 66