# Why is PlotRange->All and Automatic in DensityPlot so different?

Consider the following code:

\[Psi][{n_, l_, m_}, {r_, \[Theta]_, \[Phi]_}] :=
With[{\[Rho] = 2 r/(n a)},
Sqrt[(2/(n a))^3 (n - l - 1)!/(2 n (n + l)!)] Exp[-\[Rho]/
2] \[Rho]^
l LaguerreL[n - l - 1, 2 l + 1, \[Rho]] SphericalHarmonicY[l,
m, \[Theta], \[Phi]]];
factor[n_] := 15 n;
n = 3; l = 1; m = 0; a = 1;
For[n = 1, n < 3, n++,
For[l = 0, l < n, l++,
For[m = 0, m <= l, m++,
g = DensityPlot[
4 \[Pi] (x^2 + y^2 +
z^2) (Abs@\[Psi][{n, l, m}, {Sqrt[x^2 + y^2 + z^2],
ArcTan[z, Sqrt[x^2 + y^2]],
ArcTan[x, y]}])^2 /. {y -> 0}, {x, -factor[n] a,
factor[n] a},
{z, -factor[n] a, factor[n] a}, Mesh -> False, Frame -> False,
PlotPoints -> 200, ColorFunctionScaling -> True,
ColorFunction -> "SunsetColors",
PlotRange -> All, PlotLabel ->
Style[
"(" <> ToString[n] <> "," <> ToString[l] <> "," <>
ToString[m] <> ")",
FontSize -> 24]];
Print[g];
]
]
]


If I change PlotRange->All to PlotRange->Automatic, I'll get my favorite size, but the quality of output is not as well as that with "All". But the size of plot is too small with the first one. Is there any way to take an output with the size of "Automatic" but with the quality of "All"?

• do you get what you need if you use PlotRange -> {## & @@ ({#, #} &@{-#, #} &@factor[n] a/2), All}?
– kglr
Nov 19, 2018 at 2:53
• Yes, it worked. @kglr Nov 19, 2018 at 2:57
• Can you explain it? I'd like to know how your command worked. @kglr Nov 19, 2018 at 3:08
• Saeid, I just used explicit ranges for horizontal and vertical coordinates. See PlotRange >> Details on how Automatic, All, Full etc work.
– kglr
Nov 19, 2018 at 4:12
• @kglr I mean those symbols like ## and @ Nov 19, 2018 at 5:00

indices = Flatten[Table[{n, l, m}, {n, 1, 2}, {l, 0, n - 1}, {m, 0, l}], 2];
Row @ Table[DensityPlot[4 π (x^2 + y^2 + z^2) (Abs@ψ[i,
{Sqrt[x^2 + y^2 + z^2], ArcTan[z, Sqrt[x^2 + y^2]], ArcTan[x, y]}])^2 /. {y -> 0},
{x, -factor[i[[1]]] a, factor[i[[1]]] a}, {z, -factor[i[[1]]] a, factor[i[[1]]] a},
Mesh -> False, Frame -> False, PlotPoints -> 200,
ColorFunctionScaling -> True, ColorFunction -> "SunsetColors",
PlotRange -> {{-#, #} &@(factor[i[[1]]] a/2), {-#, #} &@(factor[i[[1]]] a/2), All},
ImageSize -> 250,
PlotLabel -> Style["(" <> ToString[i[[1]]] <> "," <> ToString[i[[2]]] <> "," <>
ToString[i[[3]]] <> ")", FontSize -> 24]], {i, indices}]


Alternatively, you can use PlotRange -> All and use a/2 instead of a in setting x and z ranges:

Row@Table[DensityPlot[4 π (x^2 + y^2 + z^2) (Abs@ψ[i,
{Sqrt[x^2 + y^2 + z^2], ArcTan[z, Sqrt[x^2 + y^2]], ArcTan[x, y]}])^2 /. {y -> 0},
{x, -factor[i[[1]]] a/2, factor[i[[1]]] a/2},
{z, -factor[i[[1]]] a/2, factor[i[[1]]] a/2},
Mesh -> False, Frame -> False, PlotPoints -> 200,
ColorFunctionScaling -> True, ColorFunction -> "SunsetColors",
PlotRange -> All, ImageSize -> 250,
PlotLabel -> Style["(" <> ToString[i[[1]]] <> "," <> ToString[i[[2]]] <> "," <>
ToString[i[[3]]] <> ")", FontSize -> 24]], {i, indices}]


same picture