# Setting each "curve" on a 3D plot to be of different colour similar to that of its 2D plot

Consider the functions

\[Lambda][n_] := ((n \[Pi])/L)^2

\[ScriptCapitalX][
x_] := \[ScriptCapitalC] Cos[Sqrt[\[Lambda][n]] x]

\[ScriptCapitalT][t_] := 50 E^(-\[Lambda] t)


to give the Sum product solution

\[ScriptCapitalU][x_,
t_, \[ScriptCapitalN]_] := \[ScriptCapitalX][x] \[ScriptCapitalT][t]


Notice that the 2D and 3D plot of the Sum product solution, respective are

Plot[Evaluate@
ReplaceAll[
Table[\[ScriptCapitalX][x] \[ScriptCapitalT][t], {n, 1, 3}, {L, 1,
1}], {\[ScriptCapitalC] -> 1, \[Lambda] -> 1, t -> 0}], {x, 0,
1}, PlotLegends -> "Expressions", AxesLabel -> {"x", "t"},
PlotLabel -> "2D Plot Behaviour for \[ScriptCapitalU](x,t)"]


and

Plot3D[ReplaceAll[
Table[\[ScriptCapitalU][x, t, \[ScriptCapitalN]], {n, 1, 3}, {L, 1,
1}], {\[ScriptCapitalC] -> 1, \[Lambda] -> 1}], {t, 0, 1}, {x,
0, 1}, AxesLabel -> Automatic,
PlotLabel -> "3D Plot Behaviour for \[ScriptCapitalU](x,t)"]


If you rotate the 3D point such that the x and t plots points "towards" you, you are able to observe that they corresponds qualitatively to the 2D plot.  In the case of the 3D plot, how do I match the different colours to different "n" for n=1 to n=3?

Any help is appreciated.

• in Plot3D[...] add the options Evaluated->True or wrap the first argument with Evaluate as you did in Plot.
– kglr
Jan 22, 2018 at 8:10
• @kglr It doesn't work Jan 22, 2018 at 8:13

Plot3D[Evaluate@
ReplaceAll[Table[\[ScriptCapitalU][x, t, \[ScriptCapitalN]], {n, 1, 3}, {L, 1, 1}],
{\[ScriptCapitalC] -> 1, λ -> 1}], {t, 0, 1}, {x, 0, 1},
AxesLabel -> Automatic,
PlotLabel -> "3D Plot Behaviour for \[ScriptCapitalU](x,t)"] Note: Interestingly, the combination of options Evaluated ->True + PlotStyle -> {Red, Green, Blue}, which works in version 9, does not work in version 11.2 (on Wolfram Cloud).

• my code bellow works in version 11.2 (PC client). Jan 23, 2018 at 7:34
\[Lambda][n_] := ((n \[Pi])/L)^2
\[ScriptCapitalX][x_] := \[ScriptCapitalC] Cos[Sqrt[\[Lambda][n]] x]
\[ScriptCapitalT][t_] := 50 E^(-\[Lambda] t)
\[ScriptCapitalU][x_, t_, \[ScriptCapitalN]_] := \[ScriptCapitalX][x] \[ScriptCapitalT][t]

Plot3D[Evaluate@ (* Step 2: enforce the evaluation before configuring the colors *)
ReplaceAll[Table[\[ScriptCapitalU][x, t, \[ScriptCapitalN]], {n, 1, 3}, {L, 1, 1}], {\[ScriptCapitalC] -> 1, \[Lambda] -> 1}], {t, 0, 1}, {x, 0, 1},
AxesLabel -> Automatic, PlotLabel -> "3D Plot Behaviour for \[ScriptCapitalU](x,t)",
PlotStyle -> {Red, Green, Blue}] (* Step 1: use PlotStyle to set up color for each plot surface *) • how is this different from the earlier answer below?:)
– kglr
Jan 22, 2018 at 8:24
• @kglr maybe we submit the answer simultaneously... however, I bring out a way to customize the colors by PlotStyle. 囧rz Jan 22, 2018 at 8:26
• PureLine, thanks. Good point.
– kglr
Jan 22, 2018 at 8:37