2
$\begingroup$

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?

$\endgroup$
10
  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Dec 28 '19 at 9:37
  • $\begingroup$ @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). $\endgroup$
    – wondering
    Dec 28 '19 at 9:55
  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Dec 28 '19 at 10:46
  • $\begingroup$ @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! $\endgroup$
    – wondering
    Dec 28 '19 at 10:57
  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Dec 28 '19 at 11:06
3
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Ok, you were a little quicker:-) $\endgroup$
    – wondering
    Dec 28 '19 at 12:45
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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