Plotting an array of functions in different colors

Click For Summary
SUMMARY

This discussion addresses the issue of plotting an array of functions in different colors using Wolfram Mathematica. When functions are defined in a user-defined function, such as fnY[x_] := List[x, x*x, -x], they are plotted in a single color. To achieve multi-color plotting, users must wrap the function call in Evaluate[]. This solution effectively allows for distinct colors for each function in the array when plotted over a specified range.

PREREQUISITES
  • Familiarity with Wolfram Mathematica syntax
  • Understanding of function definitions in Mathematica
  • Knowledge of the Plot function in Mathematica
  • Basic concepts of color functions in plotting
NEXT STEPS
  • Explore the use of Evaluate[] in Mathematica for function plotting
  • Learn about custom color functions in Wolfram Mathematica
  • Investigate advanced plotting techniques in Mathematica
  • Review user-defined functions and their behavior in Mathematica
USEFUL FOR

Mathematica users, educators, and researchers looking to enhance their data visualization skills, particularly in plotting multiple functions with distinct colors.

Swamp Thing
Insights Author
Messages
1,047
Reaction score
798
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 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K