6

When a list of functions is passed to Plot in an unevaluated form (e.g. with Through), the result is a plot with single color.

Plot[Through[{Sin, Cos, Tan}[t]], {t, 0.01, 10.5}, PlotStyle -> {Red, Blue, Green}]

Mathematica graphics

However, the same list of functions, listed explicitly, gives color as expected.

Plot[{Sin[t], Cos[t], Tan[t]}, {t, 0.01, 10.5}, PlotStyle -> {Red, Blue, Green}]

Mathematica graphics

István Zachar
  • 47,032
  • 20
  • 143
  • 291
Susanta
  • 161
  • 2
  • 1
    Plot has attribute HoldAll. So, it has "the right" to not work when you don't explicitly pass it a list. Try using Evaluate@Through..., or, better still, add the undocumented option Evaluated->True – Rojo Jan 05 '13 at 06:50
  • @Rojo Ups ... I saw your comment after posting – Dr. belisarius Jan 05 '13 at 06:53
  • @belisarius, it's ok, I wasn't going to post it, glad you did – Rojo Jan 05 '13 at 06:54
  • Related: http://mathematica.stackexchange.com/q/1731/5 – rm -rf Jan 05 '13 at 07:00
  • @Hypnotoad if it's a dupe I don't think it's of that one. The best answer here, assuming he's implicitly asking how and not why, is to use Evaluated, and that isn't relevant or even mentioned in the linked question – Rojo Jan 05 '13 at 07:03
  • @Rojo: If it is not a dupe (and I failed to find one indeed, though I searched hard), we should emend this as the canonical Q/A for this often-asked question. Edited accordingly. – István Zachar Jan 05 '13 at 10:47
  • Related question: http://mathematica.stackexchange.com/q/8637/89 – István Zachar Jan 05 '13 at 10:48
  • @Rojo I agree... This one is a lot closer in intent: http://mathematica.stackexchange.com/q/3935/5 – rm -rf Jan 05 '13 at 15:55

1 Answers1

4
a[x_, y_, z_] := z; b[x_, y_, z_] := z 2; c[x_, y_, z_] := z 3;
Plot[Through[{a, b, c}[10, 3, t]], {t, 0.01, 10.5}, 
 PlotStyle -> {Red, Blue, Green}, Evaluated -> True]

Mathematica graphics

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • 1
    Maybe one could add here that if you plan to do many such plots it's also convenient to put this at the beginning of the notebook: SetOptions[Plot,Evaluated->True]; Then you can leave out the Evaluated option in all the subsequent plots. – Jens Jan 05 '13 at 17:10