Skip to content

[Bug]: ProcessedVariable's incorrect plotting results(numeric values correct but visualization distorted) #5373

@Log-Dog012

Description

@Log-Dog012

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

Bug.ipynb

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)

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions