Skip to main content
PyBaMM provides several plotting utilities built on Matplotlib. Matplotlib is an optional dependency — it is imported lazily inside plot methods so that PyBaMM can run on headless systems without a display.
Install Matplotlib with: pip install pybamm[plot]

Quick plotting with sim.plot()

After solving, call sim.plot() to open an interactive slider plot of the default output variables:
This creates a pybamm.QuickPlot and calls dynamic_plot(), which renders a matplotlib figure with a time slider.

Choosing variables to plot

QuickPlot

pybamm.QuickPlot gives you full control over the plot configuration. It accepts solutions or simulation objects.

Constructor options

Comparing multiple solutions

Pass a list of solutions or simulations to overlay them:

Dynamic (interactive) plot

Call dynamic_plot() directly for the interactive slider:
Or use the module-level shortcut:

Static plot at a fixed time

Use plot(t) to render the figure at a single time point (in the solution’s time unit):

Voltage components

pybamm.plot_voltage_components breaks down the terminal voltage into its contributing overpotentials:
You can also pass a Solution object:
Options:
This is accessible from the Simulation object too:

Summary variables

For multi-cycle experiments, pybamm.plot_summary_variables plots cycle-level degradation metrics:
Default variables plotted:
  • 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 [%]
  • Stoichiometric limits x_100, x_0, y_100, y_0
Custom variables:
Compare multiple cycling simulations:

2D plots

For spatially-resolved models (dimensionality > 0), use pybamm.plot2D to visualise a variable as a function of two spatial coordinates:
The x, y, and z arguments must be pybamm.Array objects. plot2D calls matplotlib.pyplot.contourf under the hood.

Creating a GIF

Generate an animated GIF of the solution evolving over time:
Or via the QuickPlot object:

Working with Matplotlib directly

You can access the underlying Matplotlib figure and axes from a QuickPlot:
Set show_plot=False in plot_voltage_components, plot_summary_variables, or plot2D when you want to combine multiple figures before calling plt.show() once at the end.