wavepacket.plot

Classes

BasePlot1D

Base class for the 1D plotters.

SimplePlot1D

Simple plot of a one-dimensional density.

StackedPlot1D

Helper class to stack multiple plots on top of each other.

Package Contents

class wavepacket.plot.BasePlot1D(state: wavepacket.grid.State, potential: wavepacket.operator.OperatorBase = None, hamiltonian: wavepacket.operator.OperatorBase = None)

Bases: abc.ABC

Base class for the 1D plotters.

The class contains common code for presenting and guessing the various parameters of the plots (x limit, y limit, conversion factors), and how to draw on a given axes. Derived classes only need to generate and maintain the figure and axes object(s).

Attributes:
xlim: list[float]

The range of the x-axis [min, max]

ylim: list[float]

The range of the y-axis of the plot [min, max]

conversion_factor: float

The factor that converts from the density to energy units. Constant 1 if no potential is plotted.

xlim
abstractmethod plot(state: wavepacket.grid.State, t: float) matplotlib.pyplot.Axes

Plots a state, possibly together with the potential.

If a potential was supplied, it is also plotted, and the density shifted by the energy given as expectation value of the Hamiltonian.

Each call to plot populates a new plot (axes); if no more axes are left, the last one is overwritten.

Parameters:
state: wp.grid.State

The state whose density is plotted.

t: float

The time at which the state applies. The time is plotted in the upper right corner.

class wavepacket.plot.SimplePlot1D(state: wavepacket.grid.State, potential: wavepacket.operator.OperatorBase = None, hamiltonian: wavepacket.operator.OperatorBase = None)

Bases: BasePlot1D

Simple plot of a one-dimensional density.

This class creates a single plot of the density of a wave function or density operator, optionally together with the potential and the state’s energy. It can be used for a quick and dirty way of showing the dynamics of a simple quantum system.

Customization of the plot is limited, see BasePlot1D for the customizable attributes. The underlying grid must be one-dimensional.

Parameters:
state: wp.State

An example state for plotting; usually the initial state. This is only used to derive some reasonable defaults for the plots.

potential: wp.operator.OperatorBase, optional

The potential that is also plotted together with the state’s density. If no potential is given, only the density is plotted.

hamiltonian: wp.operator.OperatorBase, optional

The Hamiltonian of the system, usually the time-independent part. The plotted density is shifted in y (energy) direction by the expectation value of this Hamiltonian. If no Hamiltonian is given, the potential operator stands in for the Hamiltonian.

Attributes:
figure: matplotlib.pylot.Figure

The figure that we plot on.

plot(state: wavepacket.grid.State, t: float) matplotlib.pyplot.Axes

Plots a state, possibly together with the potential.

If a potential was supplied, it is also plotted, and the density shifted by the energy given as expectation value of the Hamiltonian.

Each call to plot populates a new plot (axes); if no more axes are left, the last one is overwritten.

Parameters:
state: wp.grid.State

The state whose density is plotted.

t: float

The time at which the state applies. The time is plotted in the upper right corner.

class wavepacket.plot.StackedPlot1D(num_plots, state: wavepacket.grid.State, potential: wavepacket.operator.OperatorBase = None, hamiltonian: wavepacket.operator.OperatorBase = None)

Bases: BasePlot1D

Helper class to stack multiple plots on top of each other.

This class does two things: It creates a Matplotlib figure with multiple axes stacked on top of each other, and it provides a plot function that conveniently plots the density of a state on in subsequent of these axes.

Customization of the plots is possible but limited for ease of use. The underlying grid must be one-dimensional. See the base class BasePlot1D for the attributes to tweak the plotting behavior.

This plot helper is probably most useful for Jupyter notebooks, where all created figures are implicitly plotted after execution of a code block, and where plot “animations” are difficult.

Parameters:
num_plots: int

The number of plots to stack. Should equal the number of calls to th plot function. If the class runs out of axes to plot onto, it continues plotting on the last axes.

state: wp.grid.State

An example state for plotting; usually the initial state. This is only used to derive some reasonable defaults for the plots.

potential: wp.operator.OperatorBase, optional

The potential that is also plotted together with the state’s density. If no potential is given, only the density is plotted.

hamiltonian: wp.operator.OperatorBase, optional

The Hamiltonian of the system, usually the time-independent part. The plotted density is shifted in y (energy) direction by the expectation value of this Hamiltonian. If no Hamiltonian is given, the potential operator stands in for the Hamiltonian.

Attributes:
figure: matplotlib.pylot.Figure

The figure that we plot on.

plot(state: wavepacket.grid.State, t: float) matplotlib.pyplot.Axes

Plots a state, possibly together with the potential.

If a potential was supplied, it is also plotted, and the density shifted by the energy given as expectation value of the Hamiltonian.

Each call to plot populates a new plot (axes); if no more axes are left, the last one is overwritten.

Parameters:
state: wp.grid.State

The state whose density is plotted.

t: float

The time at which the state applies. The time is plotted in the upper right corner.