# How to accentuate subtly colored regions in DensityPlot

I'm having troubles in adjusting the colors shades/contrast/hue of the following typical plot:

As you can see, there are two dark regions above and under the central part. I need to accentuate their luminosity (on the black background/first image) to see those areas more clearly, just as shown on the Wikipedia page; see this image, for the orbital (3,1,0).

Or equivalently, darken the pale yellowish regions on the white background (second image) if possible.

The graphics have been created with Mathematica 13.2, using a version of the code from 300318:

So how can I make the darker regions to stand-out, i.e to be more visible? I prefer a dark region on a white background (like the second image), and I may accept to increase the central part too to reveal the subtle regions.

• Check ColorFunction and ColorFunctionScaling. Commented Mar 11 at 18:13
• Are your wave functions same as on Wikipedia? Commented Mar 11 at 18:27
• @azerbajdzan, yes, the plots are the same, except for the color shades.
– Cham
Commented Mar 11 at 18:29
• I think it has nothing to do with color function you use but with the definition of wave functions you use. On Wikipedia they most likely used a different definition. Commented Mar 11 at 19:23
• @azerbajdzan, nope, the wave function is exactly the same. It is given in the upper-right corner of the Wikipedia image.
– Cham
Commented Mar 11 at 20:28

Update:

Simpler version of the code with ColorFunctionScaling -> {0, Pi^2} and for some reason also plot points had to be increased to PlotPoints -> 300 to achieve the same quality.

NormFactor[n_, l_] := Sqrt[Factorial[n - l - 1]/(2 n Factorial[n + l])]

Psi[n_, l_, m_, u_, \[Theta]_, \[Phi]_] :=
NormFactor[n, l] Exp[-u/2] u^l LaguerreL[n - l - 1, 2 l + 1,
u] SphericalHarmonicY[l, m, \[Theta], \[Phi]]

u[x_, z_] := Sqrt[x^2 + z^2]
theta[x_, z_] := ArcTan[z, x]

With[{nn = 3, nl = 1, nm = 0},
DensityPlot[
Abs[Psi[nn, nl, nm, u[x, z], theta[x, z], 0]]^2, {x, -15,
15}, {z, -15, 15}, Frame -> None, Axes -> False, PlotRange -> All,
Ticks -> None, PlotPoints -> 300, ColorFunctionScaling -> {0, Pi^2},
ColorFunction -> "SunsetColors", ImageSize -> {400, 400}]]


With ColorFunction -> GrayLevel:

With ColorFunction -> (GrayLevel[1 - #] &):

Old version:

So I think that they are simply clipping the range of the color gradient (that also explain the big white areas on their images).

The constant 0.005637338004403787 is the max value of the function and the clipping constant is Pi^2 or could be just, say, 9 or 10. Also you have to use ColorFunctionScaling -> False for a proper effect of clipping of the gradient.

With[{nn = 3, nl = 1, nm = 0},
DensityPlot[Pi^2/
0.005637338004403787 Abs[
Psi[nn, nl, nm, u[x, z], theta[x, z], 0]]^2, {x, -15,
15}, {z, -15, 15}, Frame -> None, Axes -> False, PlotRange -> All,
Ticks -> None, PlotPoints -> 120, ColorFunctionScaling -> False,
ColorFunction -> "SunsetColors", ImageSize -> {400, 400}]]


My image is almost unrecognizable form the one on Wikipedia:

With ColorFunction -> ColorData[{"GrayTones", "Reverse"}] you get:

• @Cham: The real depiction is your image. They increased contrast in some parts but then loose contrast elsewhere... in the white areas which seem now be constant, but in fact they are not constant as can be seen on your original image. Commented Mar 11 at 20:44
• Please, could you explain the ColorFunctionScaling -> {0, Pi^2}? Why $\pi^2$?
– Cham
Commented Mar 12 at 12:08
• @Cham: I think it is just coincidence, I tried to find a constant that resembles the Wikipedia image the most and it turned out to be near $\pi^2$, but as I wrote also in my answer it could be 9 or 10 without too much difference. The constant just determines the clipping point in the gradient. If you use 1` as the constant you get exactly your original image without any clipping. Commented Mar 12 at 14:30
• Just for a last step polishing, what if you want to use a reversed GrayLevel as shade? Currently, the option ColorFunction -> ColorData[{"GrayTones", "Reverse"}] produces a yellowish gray. I would like to get a white background, instead of that beige looking version (see your last picture above).
– Cham
Commented Mar 12 at 15:47
• @Cham: I added those cases into the answer. Commented Mar 12 at 15:56