diff --git a/CHANGELOG.md b/CHANGELOG.md index 583f63f129..0f08fd8bc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ - Deprecated `CrateTermination` and renamed it to `CRateTermination`. ([#4834](https://github.com/pybamm-team/PyBaMM/pull/4834)) +## Bug fixes + +- Fixed interpolation bug in `pybamm.QuickPlot` with spatial variables. ([#4841](https://github.com/pybamm-team/PyBaMM/pull/4841)) + # [v25.1.1](https://github.com/pybamm-team/PyBaMM/tree/v25.1.1) - 2025-01-20 ## Features diff --git a/src/pybamm/plotting/quick_plot.py b/src/pybamm/plotting/quick_plot.py index 78dafa3b07..ee146a2002 100644 --- a/src/pybamm/plotting/quick_plot.py +++ b/src/pybamm/plotting/quick_plot.py @@ -211,8 +211,8 @@ def t_sample(sol): else: raise ValueError(f"time unit '{time_unit}' not recognized") self.time_scaling_factor = time_scaling_factor - self.min_t = min_t / time_scaling_factor - self.max_t = max_t / time_scaling_factor + self.min_t_unscaled = min_t + self.max_t_unscaled = max_t # Prepare dictionary of variables # output_variables is a list of strings or lists, e.g. @@ -496,6 +496,7 @@ def plot(self, t, dynamic=False): colors = import_optional_dependency("matplotlib", "colors") t_in_seconds = t * self.time_scaling_factor + t_in_seconds = np.clip(t_in_seconds, self.min_t_unscaled, self.max_t_unscaled) self.fig = plt.figure(figsize=self.figsize) self.gridspec = gridspec.GridSpec(self.n_rows, self.n_cols) @@ -542,10 +543,7 @@ def plot(self, t, dynamic=False): y_min, y_max = ax.get_ylim() ax.set_ylim(y_min, y_max) (self.time_lines[key],) = ax.plot( - [ - t_in_seconds / self.time_scaling_factor, - t_in_seconds / self.time_scaling_factor, - ], + [t, t], [y_min, y_max], "k--", lw=1.5, @@ -812,6 +810,14 @@ def create_gif(self, number_of_images=80, duration=0.1, output_filename="plot.gi ) ani.save(output_filename, dpi=300) + @property + def min_t(self): + return self.min_t_unscaled / self.time_scaling_factor + + @property + def max_t(self): + return self.max_t_unscaled / self.time_scaling_factor + class QuickPlotAxes: """