Mathematica Plotting an array of functions in different colors

Click For Summary
When plotting functions in Mathematica, using a literal array results in each function being displayed in different colors automatically. However, when functions are defined within a user-defined function, they are plotted in a single color despite evaluating to the same array. This behavior occurs because the plotting function does not automatically recognize the individual components of the array when it is passed as a single argument. To achieve the desired effect of different colors for each function in this scenario, wrapping the function call in Evaluate[] allows Mathematica to treat the individual functions separately, thus enabling the automatic color differentiation.
Swamp Thing
Insights Author
Messages
1,045
Reaction score
775
TL;DR
A user-defined Mathematica function returns a list (array) of functions. How to plot them in different colors?
If we plot a list of functions in a literal array, they get plotted automatically in different colors, for example:
Plot [{x,x*x,-x},{x,0,10}]

But if we get the list of functions from another user-defined function, they get plotted in a single color:

fnY[x_]:={x, x*x, -x} ... OR ... fnY[x_] := List[x, x*x, -x]

Plot[fnY[x],{x,0,10}]

... even though fnY[x] evaluates to the same array as the literal array in the first example.

Why? How can we apply different colors to an array of functions constructed in a function?
 
Physics news on Phys.org
Those discussions don't quite address the particular issue I had. After some more searching it turned out that it works if you put a Evaluate[ ] around the set of functions you want to plot.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 0 ·
Replies
0
Views
620
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K