-
-
Notifications
You must be signed in to change notification settings - Fork 738
Description
PyBaMM Version
25.12.2
Python Version
3.12.12
Describe the bug
In PyBaMM v25.12.2, when plotting ProcessedVariable data (e.g., "Power [W]") from a constant-power discharge simulation (100 W until 3.2 V) using Matplotlib:
The numeric values of the variable (accessed via .data or .entries) are correct (~100 W, with minor floating-point deviations), confirming the simulation itself works as expected.
However, direct plotting of the numpy.ndarray extracted from .data (default float64 dtype) results in a severely distorted plot—y-axis is forced to a tiny range (±0.002) instead of reflecting the actual ~96–104 W values.
Explicit type conversion to np.float16 resolves the distortion and produces a correct plot.
Notably, conversion to np.float32 (or retaining the default float64) does not fix the issue—only float16 strips the problematic hidden meta-information associated with the ProcessedVariable array, which interferes with Matplotlib’s value parsing.
I guess that this bug occurs because the ProcessedVariable-derived numpy.ndarray retains unobserved meta-information that disrupts visualization, even though the underlying numeric data remains accurate.
Steps to Reproduce
import pybamm
model = pybamm.equivalent_circuit.Thevenin()
experiment = pybamm.Experiment(
[
"Discharge at 100 W until 3.2 V",
]
)
sim = pybamm.Simulation(model, experiment=experiment)
solution=sim.solve()
output_variables = ['Power [W]']
sim.plot(output_variables=output_variables)