Skip to main content
All plotting functions require matplotlib. Install it with:
pip install pybamm[plot]

pybamm.QuickPlot

Generates a grid of subplots for a set of output variables from one or more solutions.
pybamm.QuickPlot(
    solutions,
    output_variables=None,
    labels=None,
    colors=None,
    linestyles=None,
    shading="auto",
    figsize=None,
    n_rows=None,
    time_unit=None,
    spatial_unit="um",
    variable_limits="fixed",
    n_t_linear=100,
)
solutions
Solution | Simulation | list
required
A single or list of pybamm.Solution or pybamm.Simulation objects to plot.
output_variables
list[str] | None
default:"None"
Variables to include in the plot. Defaults to a model-specific set of key outputs.
labels
list[str] | None
default:"None"
Legend labels for each solution. Defaults to the model names.
colors
list[str] | None
default:"None"
Colour cycle to use. Defaults to the active matplotlib style.
linestyles
list[str] | None
default:"[\"-\", \":\", \"--\", \"-.\"]"
Linestyle cycle.
shading
str
default:"\"auto\""
Shading mode for 2D (pcolormesh) panels.
figsize
tuple[float, float] | None
default:"None"
Figure size in inches, forwarded to plt.figure.
n_rows
int | None
default:"None"
Number of subplot rows. If None, a square-ish layout is used.
time_unit
str | None
default:"None"
Time axis unit: "hours", "minutes", or "seconds".
spatial_unit
str
default:"\"um\""
Spatial axis unit: "m", "mm", or "um".
variable_limits
str | dict
default:"\"fixed\""
Axis / colorbar limits.
  • "fixed": axes do not move as time progresses.
  • "tight": axes rescale at each time step.
  • dict: per-variable control, e.g. {"Terminal voltage [V]": (3.0, 4.2)}.
n_t_linear
int
default:"100"
Number of linearly-spaced time points added per sub-solution (when Hermite interpolation is available).

pybamm.dynamic_plot

Open an interactive slider plot.
pybamm.dynamic_plot(solutions, output_variables=None, **kwargs)
Accepts the same keyword arguments as QuickPlot. Returns the QuickPlot instance.
import pybamm

sim = pybamm.Simulation(pybamm.lithium_ion.DFN(),
                        parameter_values=pybamm.ParameterValues("Chen2020"))
sol = sim.solve([0, 3600])

pybamm.dynamic_plot(sol)

pybamm.plot

Convenience wrapper — equivalent to pybamm.QuickPlot(solutions, ...).plot(t=0) followed by plt.show().
pybamm.plot(solutions, output_variables=None, **kwargs)

pybamm.plot2D

Generate a filled contour (contourf) plot of a 2D PyBaMM array.
pybamm.plot2D(x, y, z, ax=None, show_plot=True, **kwargs)
x
pybamm.Array
required
Array for the x-axis. Shape (M, N) or (N, 1).
y
pybamm.Array
required
Array for the y-axis. Shape (M, N) or (M, 1).
z
pybamm.Array
required
Array for the z-axis (colour values). Shape (M, N).
ax
matplotlib.axes.Axes | None
default:"None"
Axis to plot on. If None, a new figure is created.
show_plot
bool
default:"true"
Whether to call plt.show(). Set to False when embedding in a larger figure.
import pybamm

x = pybamm.Array([[1, 2], [1, 2]])
y = pybamm.Array([[1, 1], [2, 2]])
z = pybamm.Array([[0.1, 0.4], [0.3, 0.9]])

pybamm.plot2D(x, y, z)

pybamm.plot_voltage_components

Decomposes the terminal voltage into its constituent overpotentials and plots them as stacked filled areas.
pybamm.plot_voltage_components(
    input_data,
    ax=None,
    show_legend=True,
    split_by_electrode=False,
    electrode_phases=("primary", "primary"),
    show_plot=True,
    **kwargs_fill,
)
input_data
pybamm.Solution | pybamm.Simulation
required
Solved simulation or solution object.
ax
matplotlib.axes.Axes | None
default:"None"
Axis to draw on. Creates a new figure if None.
show_legend
bool
default:"true"
Whether to show the legend.
split_by_electrode
bool
default:"false"
Show separate overpotentials for the negative and positive electrodes.
electrode_phases
tuple[str, str]
default:"(\"primary\", \"primary\")"
Phase labels for composite-electrode models.
show_plot
bool
default:"true"
Whether to call plt.show().
import pybamm

sim = pybamm.Simulation(
    pybamm.lithium_ion.DFN(),
    parameter_values=pybamm.ParameterValues("Chen2020"),
)
sol = sim.solve([0, 3600])
pybamm.plot_voltage_components(sol)

pybamm.plot_summary_variables

Plot summary variables (capacity fade, lithium inventory loss, etc.) across multiple cycles.
pybamm.plot_summary_variables(
    solutions,
    output_variables=None,
    labels=None,
    show_plot=True,
    **kwargs_fig,
)
solutions
pybamm.Solution | list[pybamm.Solution]
required
One or more solutions from a multi-cycle experiment.
output_variables
list[str] | None
default:"None"
Variables to plot. Defaults to capacity, lithium inventory, active material loss, and stoichiometry limits.
labels
list[str] | None
default:"None"
Legend labels for each solution.
show_plot
bool
default:"true"
Whether to call plt.show().
Default output_variables:
  • "Capacity [A.h]"
  • "Loss of lithium inventory [%]"
  • "Total capacity lost to side reactions [A.h]"
  • "Loss of active material in negative electrode [%]"
  • "Loss of active material in positive electrode [%]"
  • "x_100", "x_0", "y_100", "y_0"

pybamm.close_plots

Close all open matplotlib figures.
pybamm.close_plots()

Build docs developers (and LLMs) love