# Problems with plotting spherical harmonics

I have tried to graph the real angular functions of the px and py atomic orbitals, using the Mathematica command SphericalHarmonicY, but for some reason, in both cases I get the graphs along the x-axis:

Y[l_, m_, theta_, phi_] :=
Re[SphericalHarmonicY[l, m, theta, phi]]*
Re[SphericalHarmonicY[l, m, theta, phi]]

Row[{
SphericalPlot3D[
Y[1, -1, theta, phi], {theta, 0, Pi}, {phi, 0, 2*Pi},
PlotRange -> All,
AxesLabel -> {Style["x", Medium], Style["y", Medium],
Style["z", Medium]}, ImageSize -> Medium],
SphericalPlot3D[Y[1, 1, theta, phi], {theta, 0, Pi}, {phi, 0, 2*Pi},
PlotRange -> All,
AxesLabel -> {Style["x", Medium], Style["y", Medium],
Style["z", Medium]}, ImageSize -> Medium]
}]


Something different than if I graph the functions "manually":

fpx[theta_, phi_] := (Sqrt[3]*Sin[theta]/2*Cos[phi]/Sqrt[Pi])^2;
fpy[theta_, phi_] := (Sqrt[3]*Sin[theta]/2*Sin[phi]/Sqrt[Pi])^2;

Row[{
SphericalPlot3D[fpx[theta, phi], {theta, 0, Pi}, {phi, 0, 2*Pi},
PlotRange -> All,
AxesLabel -> {Style["x", Medium], Style["y", Medium],
Style["z", Medium]}, ImageSize -> Medium],
SphericalPlot3D[fpy[theta, phi], {theta, 0, Pi}, {phi, 0, 2*Pi},
PlotRange -> All,
AxesLabel -> {Style["x", Medium], Style["y", Medium],
Style["z", Medium]}, ImageSize -> Medium]
}]


Do you know what I could be doing wrong?

Your definition of Y makes no sense. You are completely disregarding the imaginary parts of the spherical harmonics. They need to be added/subtracted as complex numbers in order to get the $$p_x$$ and $$p_y$$ orbitals.

Did you mean something like this?

px[θ_, φ_] = SphericalHarmonicY[1, -1, θ, φ] -
SphericalHarmonicY[1, 1, θ, φ] // FullSimplify;

py[θ_, φ_] = SphericalHarmonicY[1, -1, θ, φ] +
SphericalHarmonicY[1, 1, θ, φ] // FullSimplify;

pz[θ_, φ_] = SphericalHarmonicY[1, 0, θ, φ] // FullSimplify;

SphericalPlot3D[Abs[px[θ, φ]]^2, {θ, 0, π}, {φ, 0, 2 π}, PlotRange -> All]


SphericalPlot3D[Abs[py[θ, φ]]^2, {θ, 0, π}, {φ, 0, 2 π}, PlotRange -> All]


SphericalPlot3D[Abs[pz[θ, φ]]^2, {θ, 0, π}, {φ, 0, 2 π}, PlotRange -> All]