Animation
Animations of time-propagated wavepackets.
The functions here return :class:matplotlib.animation.FuncAnimation
objects. In a Jupyter notebook, display them with
IPython.display.HTML(anim.to_jshtml()); save them to a file with
anim.save("movie.mp4") (needs ffmpeg) or anim.save("movie.gif").
animate1d(grid, propagator, dt, n_frames, steps_per_frame=1, scale_pot=None, show_re_im=False, show_initial=True, analyzers=None, interval=40, ax=None, ylim=None, close_figure=True, live=False)
Animate the propagation of a wavepacket on a 1d grid.
Each frame is steps_per_frame time steps after the previous one. By
default the propagation is done up front and grid holds the final
state afterwards; the returned animation can then be rendered or saved
several times with identical results. With live=True the grid is
propagated while the animation is drawn instead, see below.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
Grid1d
|
The grid to propagate. |
required |
propagator
|
Propagator
|
E.g. a :class: |
required |
dt
|
complex
|
Time step. |
required |
n_frames
|
int
|
Number of frames. |
required |
steps_per_frame
|
int
|
Time steps per frame. |
1
|
scale_pot
|
float
|
Factor applied to the potential for plotting. By default, the potential is scaled such that its largest absolute (real) value matches the maximum of \(\vert\psi_0\vert^2\). |
None
|
show_re_im
|
bool
|
Also plot \(\mathrm{Re}\,\psi\) and \(\mathrm{Im}\,\psi\). |
False
|
show_initial
|
bool
|
Plot \(\vert\psi_0\vert^2\) in the background. |
True
|
analyzers
|
list of Analyzer
|
Each analyzer is called with the grid at every frame. |
None
|
interval
|
int
|
Delay between frames in milliseconds. |
40
|
ax
|
matplotlib Axes
|
Axes to draw into. A new figure is created if omitted. |
None
|
ylim
|
tuple of float
|
y axis limits. |
None
|
close_figure
|
bool
|
Close the figure so that notebooks do not show an extra static
image. Pass False to show the animation with |
True
|
live
|
bool
|
Propagate frame by frame while the animation is drawn instead of up
front. The animation then starts at once in an interactive window
( |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
anim |
FuncAnimation
|
|
complex_to_rgb(psi, vmax=None)
Color a complex array: hue shows the phase, brightness the modulus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
complex array
|
|
required |
vmax
|
float
|
Modulus mapped to full brightness; defaults to max(|psi|). |
None
|
animate2d(grid, propagator, dt, n_frames, steps_per_frame=1, mode='density', potential_levels=5, cmap='magma', vmax=None, analyzers=None, interval=40, ax=None, close_figure=True, live=False)
Animate the propagation of a wavepacket on a 2d grid.
As in :func:animate1d, the propagation is done up front and grid
holds the final state afterwards, unless live=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
Grid2d
|
The grid to propagate. |
required |
propagator
|
Propagator
|
E.g. a :class: |
required |
dt
|
complex
|
Time step. |
required |
n_frames
|
int
|
Number of frames. |
required |
steps_per_frame
|
int
|
Time steps per frame. |
1
|
mode
|
(density, phase)
|
Show \(\vert\psi\vert^2\) with a colormap, or \(\psi\) with the phase as hue and \(\vert\psi\vert\) as brightness. |
"density"
|
potential_levels
|
int or sequence
|
Contour levels of the real part of the potential drawn on top; 0 or None for no contours. |
5
|
cmap
|
str
|
Colormap for mode "density". |
'magma'
|
vmax
|
float
|
Value for full color (density) or brightness (modulus); defaults to the maximum of the initial state. |
None
|
analyzers
|
list of Analyzer
|
Each analyzer is called with the grid at every frame. |
None
|
interval
|
int
|
Delay between frames in milliseconds. |
40
|
ax
|
matplotlib Axes
|
Axes to draw into. A new figure is created if omitted. |
None
|
close_figure
|
bool
|
Close the figure so that notebooks do not show an extra static image. |
True
|
live
|
bool
|
Propagate while the animation is drawn, see :func: |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
anim |
FuncAnimation
|
|