Visualizing Hydrogen Orbitals in 3D with Python
- Chaitanya Singh
- Jul 22
- 2 min read

When you first encounter textbook diagrams of hydrogen’s s‑, p‑, and d‑orbitals, they’re usually neat black-and‑white sketches. But what if you could spin those shapes in 3D and really see where the electron “cloud” is densest? This project does exactly that, using pure Python plus SciPy and Matplotlib, it samples the hydrogen wavefunction on a 3D grid and renders the regions of highest probability density against a sleek black background.
The Core Idea
Wavefunction ψ<sub>nlm</sub>
Defined by three quantum numbers: n (energy level), l (angular momentum), and m (magnetic orientation).
Factorizes into a radial part, R<sub>nl</sub>(r), and an angular part, Y<sub>l</sub><sup>m</sup>(θ,φ).
Probability Density |ψ|²
Tells us where the electron is most likely to be found.
We normalize it so the maximum value is 1, then choose a threshold (e.g., 0.1) to filter out low‑density points.
3D Sampling
Build a uniform cubic grid of points (for example, 120×120×120).
Convert each (x,y,z) to spherical (r,θ,φ), compute ψ and then |ψ|².
Keep only the points above the chosen density threshold.
Behind the Scenes: Key Functions
R_nl(n, l, r)
Computes the normalized radial component using associated Laguerre polynomials and an exponential decay.
psi_nlm(n, l, m, coords)
Combines R_nl with SciPy’s sph_harm to yield the full complex wavefunction at each point.
sample_orbital(...)
Builds the grid, evaluates |ψ|², normalizes, and applies the density cutoff.
plot_3d_scatter_black(...)
Creates a Matplotlib 3D scatter plot on a black canvas, using the “plasma” colormap for high contrast.
Use case
Intuition and Teaching: Seeing orbitals in full 3D helps bridge the gap between equations and physical intuition.
Quick Validation: Compare your analytic expectations (nodal planes, lobes orientation) to what actually renders.
Extensibility: Once you’ve got the basic pipeline, you can animate time‑dependent superpositions, swap in different potentials, or export your point cloud to VR environments.
留言