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

Modifies QuickPlot.plot to take a list of times and show superimposed plots in case of 1D variables. #4529

Merged
merged 15 commits into from
Nov 22, 2024
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Added phase-dependent particle options to LAM ([#4369](https://github.com/pybamm-team/PyBaMM/pull/4369))
- Added a lithium ion equivalent circuit model with split open circuit voltages for each electrode (`SplitOCVR`). ([#4330](https://github.com/pybamm-team/PyBaMM/pull/4330))
- Added the `pybamm.DiscreteTimeSum` expression node to sum an expression over a sequence of data times, and accompanying `pybamm.DiscreteTimeData` class to store the data times and values ([#4501](https://github.com/pybamm-team/PyBaMM/pull/4501))
- Modified `quick_plot.plot` to accept a list of times and generate superimposed graphs for specified time points.([#4529](https://github.com/pybamm-team/PyBaMM/pull/4529))
medha-14 marked this conversation as resolved.
Show resolved Hide resolved

## Optimizations

Expand Down
10 changes: 5 additions & 5 deletions src/pybamm/plotting/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ def reset_axis(self):
): # pragma: no cover
raise ValueError(f"Axis limits cannot be NaN for variables '{key}'")

def plot(self, t, dynamic=False):
def plot(self, t: float | list[float], dynamic: bool = False):
medha-14 marked this conversation as resolved.
Show resolved Hide resolved
"""Produces a quick plot with the internal states at time t.

Parameters
----------
t : float or list
Dimensional time (in 'time_units') at which to plot. Can be a single time or a list of times.
t : float or list of float
Dimensional time (in 'time_units') at which to plot. Can be a single time or a list of times.
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
dynamic : bool, optional
Determine whether to allocate space for a slider at the bottom of the plot when generating a dynamic plot.
If True, creates a dynamic plot with a slider.
Expand All @@ -494,7 +494,7 @@ def plot(self, t, dynamic=False):
plt = import_optional_dependency("matplotlib.pyplot")
gridspec = import_optional_dependency("matplotlib.gridspec")

if isinstance(t, (int, float)):
if not isinstance(t, list):
t = [t]

self.fig = plt.figure(figsize=self.figsize)
Expand Down Expand Up @@ -597,7 +597,7 @@ def plot(self, t, dynamic=False):
spatial_vars = self.spatial_variable_dict[key]
variable = variable_lists[0][0]

for _idx, t_single in enumerate(t):
for t_single in t:
t_in_seconds = t_single * self.time_scaling_factor
x = self.first_spatial_variable[key]
y = self.second_spatial_variable[key]
Expand Down
Loading