# How do I choose in a 3d plot of 2 functions the color of the second one, if I only plot 1 function?

Let us consider the following 3d plot:

Plot3D[{x, y}, {x, 0, 1}, {y, 0, 1}]

resulting in a plot where separate colors are used for each plot. What if I only want to plot one function, but like the color of the second plot in the previous example and want to use it for it? Is there a SIMPLE and NEAT way how to achieve this?

• This answer shows how to retrieve the default plot style: ChartingResolvePlotTheme[Automatic, Plot3D]. You can pick the 2nd one to reproduce the blue style you see by default. Commented Dec 28, 2019 at 9:37
• @Szabolcs Do you mean Plot3D[x, {x, 0, 1}, {y, 0, 1}, PlotStyle -> ColorData[2, "ColorList"]] ? This does not give me the desired result (Mathematica 12.0.0). Commented Dec 28, 2019 at 9:55
• No, use the command form my first comment to get the styles specific to Plot3D. It's not just a colour, it's also some lighting. Commented Dec 28, 2019 at 10:46
• @Szabolcs Yes, I tried putting the command before the mentioned Plot3D command but that did not work either. So how do I use the command? Could you please give me the full code I need to use? Thank you! Commented Dec 28, 2019 at 10:57
• Please read the answer I linked carefully, and in full. It does not tell you to run ResolvePlotTheme before the Plot3D. It explains that you can list the default plots styles with ChartingResolvePlotTheme[Automatic, Plot3D]. Take the 2nd plot style from that output of that command and use it. Commented Dec 28, 2019 at 11:06

Here are three short ways of doing it:

defStyle2 = ("DefaultPlotStyle" /. (Method /. ChartingResolvePlotTheme[Automatic, Plot3D]))[[2]];
defStyle2 = ChartingResolvePlotTheme[Automatic, Plot3D][[-1, -1, 4, 2, 2]];
defStyle2 = ChartingResolvePlotTheme[Automatic, Plot3D][[5, 2, 4, 2, 2]];

Plot3D[y, {x, 0, 1}, {y, 0, 1}, PlotStyle -> defStyle2]

For more in depth examples, see these questions:

What are the standard colors for plots in Mathematica 10?

The default PlotStyle for Plot3D and how to replace the color

• Ok, you were a little quicker:-) Commented Dec 28, 2019 at 12:45

So, with a little "cheating", a solution could be:

Plot3D[{"", y}, {x, 0, 1}, {y, 0, 1}]

Longer but without cheating (see WeavingBird1917 comment):

Plot3D[y, {x, 0, 1}, {y, 0, 1}, PlotStyle -> ("DefaultPlotStyle" /. (Method /. ChartingResolvePlotTheme[Automatic, Plot3D]))[[2]]]

Alternatively,

Plot3D[y, {x, 0, 1}, {y, 0, 1}, PlotStyle -> Charting`ResolvePlotTheme[Automatic, Plot3D][[5, 2, 4, 2, 2]]]

See discussion below the question for yet another option.