Visualization¶
Generated from the docstrings in the source code.
volume_3d
¶
3D volumetric rendering of wavefunctions: nested |ψ|² isosurfaces extracted with marching cubes, coloured by the local quantum phase arg ψ and lit with a simple Lambert model. Supports orbiting-camera animations (MP4/GIF) and interactive HTML export (Plotly).
Requires scikit-image (marching cubes); Plotly is only needed for HTML export.
IsosurfaceRenderer(grid: Grid3D, levels: Sequence[float] = (0.5, 0.15, 0.03), alphas: Optional[Sequence[float]] = None, color_by: str = 'phase', reference_peak: Optional[float] = None, potential=None, potential_level: float = 0.5, theme: str = 'dark', step_size: int = 1, figsize=(9, 8), light_direction=(0.4, -0.5, 0.75), show_axes: bool = True, zoom: float = 1.15, phase_cmap: str = PHASE_CMAP)
¶
Render |ψ(x, y, z)|² as nested translucent isosurfaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
Grid3D
|
|
required |
levels
|
sequence of float
|
Isosurface levels as fractions of the reference peak density. |
(0.5, 0.15, 0.03)
|
alphas
|
sequence of float
|
Opacity per level (defaults fade from opaque inner to faint outer). |
None
|
color_by
|
(phase, level)
|
'phase' colours each face by arg ψ on a cyclic map; 'level' uses one colour per isosurface. |
'phase'
|
reference_peak
|
float
|
Density that |
None
|
potential
|
Potential
|
Drawn as a grey translucent isosurface at |
None
|
step_size
|
int
|
Marching-cubes step (2 roughly quarters the triangle count). |
1
|
Source code in quantumlab/visualization/volume_3d.py
draw(psi: np.ndarray, t: Optional[float] = None, elev: float = 22.0, azim: float = -58.0, title: Optional[str] = None, note: Optional[str] = None, overlays: Optional[Sequence[dict]] = None)
¶
Draw one frame (re-uses the figure across calls) and return it.
overlays is a list of extra opaque surfaces drawn underneath the
translucent density shells, each a dict with keys field (array on
the grid), level, and optionally color and alpha. Example:
vortex cores as an isosurface of the normalised density.
Source code in quantumlab/visualization/volume_3d.py
IsosurfaceAnimation(output_path, grid: Grid3D, n_frames: int, fps: int = 20, dpi: int = 100, elev: float = 22.0, azim_start: float = -60.0, orbit_degrees: float = 90.0, title: Optional[str] = None, note: Optional[str] = None, elev_end: Optional[float] = None, **renderer_kwargs)
¶
Streaming MP4/GIF writer: frames are rendered as they are added, so a long high-resolution simulation never has to keep its snapshots in memory.
Usage::
with IsosurfaceAnimation('out.mp4', grid, n_frames=120, reference_peak=p0) as anim:
for ...:
anim.add_frame(wf.psi, t)
The camera orbits from azim_start by orbit_degrees over n_frames;
if elev_end is given the elevation moves linearly from elev to it.
Source code in quantumlab/visualization/volume_3d.py
extract_isosurface(field: np.ndarray, level: float, grid: Grid3D, step_size: int = 1)
¶
Marching-cubes isosurface of a scalar field sampled on grid.
Returns (vertices in physical coordinates, faces, unit face normals), or None if the level is outside the field range.
Source code in quantumlab/visualization/volume_3d.py
animate_isosurfaces(snapshots: Sequence[np.ndarray], times: Sequence[float], grid: Grid3D, output_path, fps: int = 20, dpi: int = 100, elev: float = 22.0, azim_start: float = -60.0, orbit_degrees: float = 90.0, title: Optional[str] = None, note: Optional[str] = None, fixed_scale: bool = True, progress: bool = True, **renderer_kwargs)
¶
Render a series of 3D wavefunctions (complex arrays on grid) to MP4 or
GIF while the camera orbits by orbit_degrees over the clip.
With fixed_scale=True the isosurface levels refer to the peak density
of the whole series, so shrinking/spreading is shown faithfully.
Source code in quantumlab/visualization/volume_3d.py
export_interactive_html(snapshots: Sequence[np.ndarray], times: Sequence[float], grid: Grid3D, output_path, level: float = 0.1, stride: int = 2, title: str = 'QuantumLab — 3D wavefunction')
¶
Interactive, rotatable HTML (Plotly Mesh3d) of one |ψ|² isosurface per
snapshot, coloured by phase, with a time slider. stride subsamples the
grid to keep the file small. Plotly.js is loaded from its CDN.
Source code in quantumlab/visualization/volume_3d.py
plots_1d
¶
plots_2d
¶
plot_density_2d(wf, potential=None, title: str = '2D Probability Density $|\\Psi(x,y)|^2$', save_path: str = None, show: bool = True, theme: str = 'light', log_scale: bool = False)
¶
Heatmap of the 2D probability density |ψ(x,y)|² with optional potential overlay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wf
|
WaveFunction2D
|
The wavefunction to visualise. |
required |
potential
|
Potential
|
If provided, draws a contour overlay of V(x, y). |
None
|
title
|
str
|
Plot title. |
'2D Probability Density $|\\Psi(x,y)|^2$'
|
save_path
|
str
|
File path to save the figure (PNG, PDF, etc.). |
None
|
show
|
bool
|
Whether to call plt.show(). |
True
|
theme
|
str
|
'light' or 'dark'. |
'light'
|
log_scale
|
bool
|
Use logarithmic colour scale (useful for tunnelling tails). |
False
|
Source code in quantumlab/visualization/plots_2d.py
plot_density_snapshots_2d(wf_list, times, potential=None, ncols: int = 4, title: str = '2D Wave Packet Evolution', save_path: str = None, show: bool = True, theme: str = 'light')
¶
Grid of |ψ|² heatmap snapshots at different times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wf_list
|
list of WaveFunction2D
|
Ordered list of wavefunctions (one per snapshot). |
required |
times
|
array - like
|
Corresponding time values for axis labels. |
required |
ncols
|
int
|
Number of columns in the snapshot grid. |
4
|
Source code in quantumlab/visualization/plots_2d.py
plot_orthogonal_slices_3d(wf3d, potential=None, title: str = '3D Wave Packet — Orthogonal Slices', save_path: str = None, show: bool = True, theme: str = 'light')
¶
Three-panel plot showing |ψ|² slices through the centroid of a 3D wavefunction: XY (z=centre), XZ (y=centre), YZ (x=centre).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wf3d
|
WaveFunction3D
|
The 3D wavefunction to slice. |
required |
potential
|
Potential
|
Draws a contour overlay on each panel. |
None
|
Source code in quantumlab/visualization/plots_2d.py
plots_3d
¶
animation
¶
Time-evolution animation exporters for 2D and 3D simulations. Requires ffmpeg for MP4 output; falls back to GIF via Pillow.
WavePacketAnimator(wf_series, times, grid, potential=None, theme='dark', log_scale=False, fps=30)
¶
Deterministic animation pipeline. No randomness in frame generation. Global colour scale is pre-computed across all frames for consistency.