Skip to content

Commit

Permalink
Fix plotting interpolation bug with spatial variables (pybamm-team#4841)
Browse files Browse the repository at this point in the history
* fix plotting interpolation bug

* Update CHANGELOG.md
  • Loading branch information
MarcBerliner authored and RohitP2005 committed Feb 13, 2025
1 parent 636c90e commit de2699b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions src/pybamm/plotting/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
"""
Expand Down

0 comments on commit de2699b

Please sign in to comment.