2

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?

wondering
  • 595
  • 3
  • 18
  • This answer shows how to retrieve the default plot style: Charting`ResolvePlotTheme[Automatic, Plot3D]. You can pick the 2nd one to reproduce the blue style you see by default. – Szabolcs Dec 28 '19 at 09: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). – wondering Dec 28 '19 at 09: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. – Szabolcs Dec 28 '19 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! – wondering Dec 28 '19 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 Charting`ResolvePlotTheme[Automatic, Plot3D]. Take the 2nd plot style from that output of that command and use it. – Szabolcs Dec 28 '19 at 11:06
  • Plot3D[y, {x, 0, 1}, {y, 0, 1}, PlotStyle -> Directive[Specularity[GrayLevel[1], 3], RGBColor[ 0.368417, 0.506779, 0.709798], Lighting -> {{"Ambient", RGBColor[ 0.196998383`, 0.252204821, 0.333209402`]}, {"Directional", RGBColor[ 0.15473514`, 0.21284718`, 0.29811516`], ImageScaled[{0, 2, 2}]}, {"Directional", RGBColor[ 0.15473514`, 0.21284718`, 0.29811516`], ImageScaled[{2, 2, 2}]}, {"Directional", RGBColor[ 0.15473514`, 0.21284718`, 0.29811516`], ImageScaled[{2, 0, 2}]}}]] – Szabolcs Dec 28 '19 at 11:07
  • Thanks, but that is an awfully extensive, complicated way to achieve that. Isn't there a shortcut? I think it is then better to use the following command with an empty first plot: Plot3D[{"", y}, {x, 0, 1}, {y, 0, 1}]. I would even put it here as a simple answer, if the question was not closed. What do you think? – wondering Dec 28 '19 at 11:23
  • Plot3D[y, {x, 0, 1}, {y, 0, 1}, PlotStyle -> ("DefaultPlotStyle" /. (Method /. Charting`ResolvePlotTheme[Automatic, Plot3D]))[[2]]]

    Related question: https://mathematica.stackexchange.com/questions/172147/the-default-plotstyle-for-plot3d-and-how-to-replace-the-color

    –  Dec 28 '19 at 12:20
  • Or shorter but less readable: Plot3D[y, {x, 0, 1}, {y, 0, 1}, PlotStyle -> Charting`ResolvePlotTheme[Automatic, Plot3D][[5, 2, 4, 2, 2]]] –  Dec 28 '19 at 12:35
  • @WeavingBird1917 Thank you, that is much better! – wondering Dec 28 '19 at 12:38

2 Answers2

3

Here are three short ways of doing it:

defStyle2 = ("DefaultPlotStyle" /. (Method /. Charting`ResolvePlotTheme[Automatic, Plot3D]))[[2]];
defStyle2 = Charting`ResolvePlotTheme[Automatic, Plot3D][[-1, -1, 4, 2, 2]];
defStyle2 = Charting`ResolvePlotTheme[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

2

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 /. Charting`ResolvePlotTheme[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.

wondering
  • 595
  • 3
  • 18