Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plotting interpolation bug with spatial variables #4841

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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