Is it possible to put two functions in densityplot like in the plot?
I like Jason B.'s answer. Here is a quick to type in alternative:
ImageAdd[Image[f1], Image[f2]]
Note that the axes ticks and values get blurry.
I assume in other cases this would be better:
ImageAdjust[ImageAdd[Image[f1], Image[f2]]]
If you consider a DensityPlot
of two functions to be similar to a Plot3D
of two functions viewed from the top, then
DensityPlot[
Max[ψ[-500, -500], ψ[500, 500]], {x, -1000, 1000}, {y, -1000, 1000}, PlotPoints -> 100,
ColorFunction -> "SunsetColors", PlotRange -> All,
Exclusions -> None]
gives you the expected output.
This also works for functions with overlapping features:
DensityPlot[Max[Sin[x], Cos[x]], {x, 0, 2 Pi}, {y, 0, 2 Pi},
PlotPoints -> 100, ColorFunction -> "SunsetColors", PlotRange -> All, Exclusions -> None]
The corresponding Plot3D
for comparison:
Plot3D[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, {y, 0, 2 Pi},
ColorFunction -> "SunsetColors", Boxed -> False, ViewPoint -> Top]
However, if your expect a "DensityPlot
of two function" to give you the total combined density, then using Plus
instead of Max
is the appropriate approach.
In more involved visualization situations one can use Piecewise
to combine the two functions in one DensityPlot
or create two DensityPlot
s, restrict each to a certain area using the RegionFunction
option or by specifying a region (documentation examples), and then combine both using Show
.