How does one splice together parts of two 3D density plots, without changing the original colors?
I think Piecewise
is all what you need:
f2[x_, y_, t_] =
Piecewise[{{Re[f[x, y, t]], 0 <= t < 59}, {Re[g[x, y, t]], 59 <= t <= 60}}]
DensityPlot3D[f2[x, y, t], {x, -60, 60}, {y, -60, 60}, {t, 0, 60},
ColorFunction -> "Rainbow", AxesLabel -> {"x", "y", "t"}]
Note: as C. E. correctly notes in the comments, this solution works only for the cases when resulting Piecewise
function has the same range of values in the given domain as both the original functions. If not, the coloring will change due to the default ColorFunctionScaling -> True
option. To workaround this one should set ColorFunctionScaling -> False
for all three plots and define appropriate custom ColorFunction
for them. The latter usually (depending on the behavior of the objective functions and user's goals) should cover the whole range of values of the original objective functions in the given domain. Of course, all these complications are necessary only if the original two plots are to be demonstrated alongside with the third plot, and hence all three plots must have the same color scale (i.e. any given color must correpond to the same value in all plots).
Note 2: as C. E. explains in the comments, his understanding of the situation is opposite to mine. I assume that all three plots must have the same color scale, while his understanding is that two original plots may have different color scales and should be combined into one plot keeping original colors (what leads to confusing sutuation, because in different parts of the resulting plot any given color may correspond to different values of the functions). Both interpretations are valid given the original formulation of the question, and in the specific case presented in OP seemingly lead to the same resulting plot. But one should note that these two approaches are entirely different and will lead to different results in the general case.
Here I use other ranges for the Piecewise
just to demonstrate that the colors are really preserved:
f[x_, y_, t_] = (E^(-((-10 + x)^2/(4 + 2 I t)) - (10 + y)^2/(4 + 2 I t)) Sqrt[
2/\[Pi]])/(2 + I t);
g[x_, y_, t_] = (E^(-(x^2/(4 + 2 I (60 - t))) - y^2/(4 + 2 I (60 - t))) Sqrt[
2/\[Pi]])/(2 + I (60 - t));
f2[x_, y_, t_] =
Piecewise[{{Re[f[x, y, t]], 0 <= t < 30}, {Re[g[x, y, t]], 30 <= t <= 60}}];
p1 = DensityPlot3D[Re[f[x, y, t]], {x, -60, 60}, {y, -60, 60}, {t, 0, 60},
ColorFunction -> "Rainbow", AxesLabel -> {"x", "y", "t"}, ImageSize -> 300];
p2 = DensityPlot3D[Re[g[x, y, t]], {x, -60, 60}, {y, -60, 60}, {t, 0, 60},
ColorFunction -> "Rainbow", AxesLabel -> {"x", "y", "t"}, ImageSize -> 300];
p3 = DensityPlot3D[f2[x, y, t], {x, -60, 60}, {y, -60, 60}, {t, 0, 60},
ColorFunction -> "Rainbow", AxesLabel -> {"x", "y", "t"}, ImageSize -> 300];
Row[{p1, p2, p3}]
Just using Show
should do it:
dp1 = DensityPlot3D[
Re[f[x, y, t]],
{x, -60, 60}, {y, -60, 60}, {t, 0, 30},
ColorFunction -> "AlpineColors",
AxesLabel -> {"x", "y", "t"}
];
dp2 = DensityPlot3D[
Re[g[x, y, t]],
{x, -60, 60}, {y, -60, 60}, {t, 30, 60},
ColorFunction -> "SolarColors",
AxesLabel -> {"x", "y", "t"}
];
Show[
dp1,
dp2,
PlotRange -> {{-60, 60}, {-60, 60}, {0, 60}}
]