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.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pybamm-team/PyBaMM/llms.txt
Use this file to discover all available pages before exploring further.
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:
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
| Parameter | Description | Default |
|---|---|---|
solutions | Solution(s) or Simulation(s) to plot | required |
output_variables | List of variable names | model defaults |
labels | Legend labels for each solution | model names |
colors | Color cycle | ["r", "b", "k", "g", "m", "c"] |
linestyles | Linestyle cycle | ["-", ":", "--", "-."] |
figsize | Figure size (width, height) | auto |
n_rows | Number of subplot rows | auto (square layout) |
time_unit | "hours", "minutes", or "seconds" | auto |
spatial_unit | "m", "mm", or "um" | "um" |
variable_limits | Axis limits: "fixed", "tight", or a dict | "fixed" |
Comparing multiple solutions
Pass a list of solutions or simulations to overlay them:Dynamic (interactive) plot
Calldynamic_plot() directly for the interactive slider:
Static plot at a fixed time
Useplot(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:
Solution object:
Simulation object too:
Summary variables
For multi-cycle experiments,pybamm.plot_summary_variables plots cycle-level degradation metrics:
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
2D plots
For spatially-resolved models (dimensionality > 0), usepybamm.plot2D to visualise a variable as a function of two spatial coordinates:
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:QuickPlot object:
Working with Matplotlib directly
You can access the underlying Matplotlib figure and axes from aQuickPlot: