Mathematica PlotStyle->{color,color,color} not working

  • Mathematica
  • Thread starter rynlee
  • Start date
  • Tags
    Mathematica
In summary, the conversation discusses an issue with plotting multiple complex functions with different colors using a list of Hue evaluations. However, the functions are all plotted with the last color in the list. The solution is to use Evaluate[Im[correlationList]] instead of just Im[correlationList] in the Plot command.
  • #1
rynlee
45
0
Hi All, running into a bit of a mathematica issue. I put the following code into plot:
Code:
Plot[Im[correlationList], {t, 0, timeEnd}, 
  PlotStyle -> ColorList]

correlationList is a list of complex functions that have been evaluated at t. It correctly plots all of them (if I change it to correlationList[[2]] for example it only plots the second function, etc., as is it plots all of the functions on the same plot)

(I've omitted PlotRange -> {Full, {-1, 1}}, ImageSize -> Large, from the above command, but that's in there too)

ColorList is a list of Hue[] evaluations, i.e.
Code:
In:ColorList
Out: {Hue[1/10],Hue[1/5],Hue[3/10],Hue[2/5],Hue[1/2],Hue[3/5],Hue[7/10],Hue[4/5],Hue[9/10],Hue[1]}

When I plot this however, it colors *all* of the curves the *last* color in the color list.

This behavior holds even when I change the PlotStyle term, for example if I use {Orange,Blue,Green} instead of ColorList, it plots *all* of the functions green, none orange or blue. So it always takes the last member of the list. I'm not sure why it's doing this.

I tried transposing ColorList (which I generate from an Array[0&,10] command, then filled in with a Do[] loop), but that just gave error messages.

Thanks for any help,

rynlee
 
Physics news on Phys.org
  • #2
I'm thinking that you might need to Plot[{Im[correlationList[[1]]], ..., Im[correlationList[[n]]]}] rather than
Plot[Im[{correlationList[[1]], ..., correlationList[[n]]} ], if you get what I mean.

So what happens if you plot Evaluate[Im[correlationList]] instead?
Or first convert it to a list, e.g. plotting I am /@ correlationList?
 
  • #3
yep the evaluate[] did it! Thanks!
 
  • #4
The final function (just to show what it should look like if anyone else has the same problem):
 

Attachments

  • Prob 2Gi.jpg
    Prob 2Gi.jpg
    27.1 KB · Views: 577
  • #5


Hi rynlee,

Thank you for reaching out about this Mathematica issue. From what you have described, it seems like there may be an error in your code or in the way you are generating your ColorList. I would suggest checking your code for any potential errors or typos, and also trying to generate the ColorList in a different way to see if that resolves the issue.

Additionally, you may want to try using specific colors instead of Hue evaluations, as that may help to pinpoint the issue. If none of these solutions work, it may be helpful to provide more specific details or share your code so that I can better assist you.

Best of luck with your Mathematica project!
 

1. Why is Mathematica not recognizing my PlotStyle colors?

There could be several reasons for this. First, make sure that the colors you are using are supported by Mathematica. You can check this by looking at the documentation for PlotStyle. Additionally, check that you are using the correct syntax for specifying multiple colors - each color should be separated by a comma. If you are still having issues, try restarting Mathematica or checking for any conflicting settings.

2. How do I change the colors of individual lines in a plot using PlotStyle?

To change the colors of individual lines in a plot, you can use the PlotStyle option in combination with the PlotLegends option. In your PlotStyle, specify a list of colors, and then in PlotLegends, specify the labels for each line with the corresponding color. This will ensure that each line is plotted with the correct color.

3. Can I use RGB or hexadecimal values for PlotStyle colors?

Yes, you can use RGB or hexadecimal values for PlotStyle colors. Simply specify the color in the appropriate format - for example, RGBColor[0, 0, 1] or RGBColor["#0000FF"]. You can also use named colors, such as Red or Blue, if you prefer.

4. How do I change the overall color of my plot using PlotStyle?

To change the overall color of your plot, you can use the PlotTheme option in combination with PlotStyle. PlotTheme allows you to specify a theme for your plot, which includes a preset color scheme. You can also customize the color scheme by specifying a list of colors in PlotStyle.

5. Why are all of my lines the same color when using PlotStyle?

If all of your lines are the same color when using PlotStyle, it is likely that you have only specified one color instead of a list of colors. Make sure to separate each color with a comma to ensure that each line is plotted with a different color. You can also try using the PlotLegends option to see if it changes the colors of your lines.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
201
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • Classical Physics
Replies
1
Views
1K
Back
Top