I have lets say three plots A, B, C. I know that in order to plot them on top of each other I can use Show function and it will show them all together, Is there a way to change the color (and/or legend) of the plots within the Show command? without going back to the original Plot for each A, B and C and changing the color and legend.

I tried something like this

Show[{A, PlotStyle -> Black}, {B, PlotStyle -> Red}, {C, PlotRange -> Pink}]

But i got an error (Show::gcomb: Could not combine the graphics objects in ).

Your help is appreciated.

  • $\begingroup$ Put PlotStyle -> correspondingstyle as option in each plot, and then use Show[A,B,C] $\endgroup$
    – Fraccalo
    Jan 30, 2020 at 18:56
  • $\begingroup$ @Fraccalo while this is what I would have suggested as well, I think that Erf does not want to go back to the individual plots and if I understand the solution has to be at the level of Show $\endgroup$ Jan 30, 2020 at 19:00
  • $\begingroup$ That is true @Darth_Bane , I don't want to go back to the each plot, $\endgroup$
    – Erfi
    Jan 30, 2020 at 19:02
  • $\begingroup$ sorry didn't read properly, see answer below. $\endgroup$
    – Fraccalo
    Jan 30, 2020 at 19:12

2 Answers 2

a = Plot[x, {x, 0, 2}];
b = Plot[x^2, {x, 0, 2}];
c = Plot[x^3, {x, 0, 2}];

defaultMMAcolor=RGBColor[0.368417, 0.506779, 0.709798]

Show[a /. {defaultMMAcolor -> Black}, 
 b /. {defaultMMAcolor -> Red}, 
 c /. {defaultMMAcolor -> Pink}]

enter image description here


Is this something that you had in mind?

Generate a random plot

A = Plot[x^3, {x, -3, 3}]

And then

Show[A /. _RGBColor -> Red]

The above is the simplest resolution I know off and I have used in the past. I found this answer on this site. I am giving the link, where you can also find more sophisticated approaches you can check

Regarding the question at the comment: is the following acceptable?

Legended[Show[A /. _RGBColor -> Red], Placed[SwatchLegend[{Red, Green, Blue}, 
    {"something"}], {1, 1}]]
  • 1
    $\begingroup$ the problem with this approach is that it changes all the colors: say for example your plot is: a = Plot[x, {x, 0, 2}, AxesStyle -> Green]; with your code the axes color would be overwritten to Red $\endgroup$
    – Fraccalo
    Jan 30, 2020 at 19:16
  • 1
    $\begingroup$ @Fraccalo that is a valid point. I did not know that because I don't change the colours of the axes. Thanks for pointing it out anyway $\endgroup$ Jan 30, 2020 at 19:19
  • $\begingroup$ @Darth_Bane thank you, this actually works. But do you know how to add legends in similar way ? $\endgroup$
    – Erfi
    Jan 30, 2020 at 19:21
  • $\begingroup$ @Erf I just want to point out that the other answer is better and more precise and I have voted for it. Just to be clear $\endgroup$ Jan 30, 2020 at 19:23
  • $\begingroup$ @Erf while I still suggest that you try the other answer as it is more complete, I think I have answered the PlotLegends comment. please have a look $\endgroup$ Jan 30, 2020 at 19:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.