Skip to content

Commit b2488ce

Browse files
authored
Merge pull request #1099 from pybamm-team/issue-1084-kwargs-sim-plot
#1084 allow kwargs to be passed to sim.plot
2 parents 5ff13ed + a83b2fb commit b2488ce

File tree

4 files changed

+59
-29
lines changed

4 files changed

+59
-29
lines changed

CHANGELOG.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Unreleased
2+
3+
## Features
4+
5+
- Allowed keyword arguments to be passed to `Simulation.plot()` ([#1099](https://github.com/pybamm-team/PyBaMM/pull/1099))
6+
7+
## Optimizations
8+
9+
## Bug fixes
10+
11+
## Breaking changes
12+
13+
- Renamed `quick_plot_vars` to `output_variables` in `Simulation` to be consistent with `QuickPlot`. Passing `quick_plot_vars` to `Simulation.plot()` has been deprecated and `output_variables` should be passed instead ([#1099](https://github.com/pybamm-team/PyBaMM/pull/1099))
14+
15+
116
# [v0.2.3](https://github.com/pybamm-team/PyBaMM/tree/v0.2.3) - 2020-07-01
217

318
This release enables the use of [Google Colab](https://colab.research.google.com/github/pybamm-team/PyBaMM/blob/master/) for running example notebooks, and adds some small new features and bug fixes.
@@ -33,7 +48,7 @@ This release enables the use of [Google Colab](https://colab.research.google.com
3348
## Breaking changes
3449

3550
- `Simulation.specs` and `Simulation.set_defaults` have been deprecated. Users should create a new `Simulation` object for each different case instead ([#1090](https://github.com/pybamm-team/PyBaMM/pull/1090))
36-
- The solution times `t_eval` must now be provided to `Simulation.solve()` when not using an experiment or prescribing the current using drive cycle data ([#1086](https://github.com/pybamm-team/PyBaMM/pull/1086))
51+
- The solution times `t_eval` must now be provided to `Simulation.solve()` when not using an experiment or prescribing the current using drive cycle data ([#1086](https://github.com/pybamm-team/PyBaMM/pull/1086))
3752

3853
# [v0.2.2](https://github.com/pybamm-team/PyBaMM/tree/v0.2.2) - 2020-06-01
3954

examples/notebooks/Getting Started/Tutorial 3 - Basic plotting.ipynb

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
{
3030
"data": {
3131
"text/plain": [
32-
"<pybamm.solvers.solution.Solution at 0x7fe21ea34c50>"
32+
"<pybamm.solvers.solution.Solution at 0x7f5a7dda5048>"
3333
]
3434
},
3535
"execution_count": 1,
@@ -666,7 +666,7 @@
666666
{
667667
"data": {
668668
"application/vnd.jupyter.widget-view+json": {
669-
"model_id": "210ea1fb46d9436e8b48f53c70b80db7",
669+
"model_id": "26530e3fbec34dfa921fda4c1490a8f5",
670670
"version_major": 2,
671671
"version_minor": 0
672672
},
@@ -679,8 +679,8 @@
679679
}
680680
],
681681
"source": [
682-
"quick_plot_vars = [\"Terminal voltage [V]\"]\n",
683-
"sim.plot(quick_plot_vars=quick_plot_vars)"
682+
"output_variables = [\"Terminal voltage [V]\"]\n",
683+
"sim.plot(output_variables=output_variables)"
684684
]
685685
},
686686
{
@@ -698,7 +698,7 @@
698698
{
699699
"data": {
700700
"application/vnd.jupyter.widget-view+json": {
701-
"model_id": "8b13649c493c4561b647cf49f3867486",
701+
"model_id": "d1d16e2c52654cf48e1d3cd398c4ed18",
702702
"version_major": 2,
703703
"version_minor": 0
704704
},
@@ -711,8 +711,8 @@
711711
}
712712
],
713713
"source": [
714-
"quick_plot_vars = [\"Electrolyte concentration [mol.m-3]\", \"Terminal voltage [V]\"]\n",
715-
"sim.plot(quick_plot_vars=quick_plot_vars)"
714+
"output_variables = [\"Electrolyte concentration [mol.m-3]\", \"Terminal voltage [V]\"]\n",
715+
"sim.plot(output_variables=output_variables)"
716716
]
717717
},
718718
{
@@ -730,7 +730,7 @@
730730
{
731731
"data": {
732732
"application/vnd.jupyter.widget-view+json": {
733-
"model_id": "b471a3ef004a422d9ad5797c74099c6b",
733+
"model_id": "3d08bfd164df409ca3838bb1edd4d4c9",
734734
"version_major": 2,
735735
"version_minor": 0
736736
},
@@ -748,13 +748,13 @@
748748
},
749749
{
750750
"cell_type": "code",
751-
"execution_count": 9,
751+
"execution_count": 7,
752752
"metadata": {},
753753
"outputs": [
754754
{
755755
"data": {
756756
"application/vnd.jupyter.widget-view+json": {
757-
"model_id": "ec65841022c74b27bc1c60757a8a3f1a",
757+
"model_id": "c248e1ccf0c34d53b5f2c0e44115e8d5",
758758
"version_major": 2,
759759
"version_minor": 0
760760
},
@@ -796,7 +796,7 @@
796796
"name": "python",
797797
"nbconvert_exporter": "python",
798798
"pygments_lexer": "ipython3",
799-
"version": "3.7.7"
799+
"version": "3.6.9"
800800
}
801801
},
802802
"nbformat": 4,

pybamm/simulation.py

+28-17
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Simulation:
6464
domain (e.g. pybamm.FiniteVolume)
6565
solver: :class:`pybamm.BaseSolver` (optional)
6666
The solver to use to solve the model.
67-
quick_plot_vars: list (optional)
67+
output_variables: list (optional)
6868
A list of variables to plot automatically
6969
C_rate: float (optional)
7070
The C_rate at which you would like to run a constant current
@@ -81,7 +81,7 @@ def __init__(
8181
var_pts=None,
8282
spatial_methods=None,
8383
solver=None,
84-
quick_plot_vars=None,
84+
output_variables=None,
8585
C_rate=None,
8686
):
8787
self.parameter_values = parameter_values or model.default_parameter_values
@@ -112,7 +112,7 @@ def __init__(
112112
self.var_pts = var_pts or self.model.default_var_pts
113113
self.spatial_methods = spatial_methods or self.model.default_spatial_methods
114114
self.solver = solver or self.model.default_solver
115-
self.quick_plot_vars = quick_plot_vars
115+
self.output_variables = output_variables
116116

117117
# Initialize empty built states
118118
self._model_with_set_params = None
@@ -531,28 +531,39 @@ def get_variable_array(self, *variables):
531531
else:
532532
return tuple(variable_arrays)
533533

534-
def plot(self, quick_plot_vars=None, testing=False):
534+
def plot(self, output_variables=None, quick_plot_vars=None, **kwargs):
535535
"""
536-
A method to quickly plot the outputs of the simulation.
536+
A method to quickly plot the outputs of the simulation. Creates a
537+
:class:`pybamm.QuickPlot` object (with keyword arguments 'kwargs') and
538+
then calls :meth:`pybamm.QuickPlot.dynamic_plot`.
537539
538540
Parameters
539541
----------
540-
quick_plot_vars: list, optional
542+
output_variables: list, optional
541543
A list of the variables to plot.
542-
testing, bool, optional
543-
If False the plot will not be displayed
544+
quick_plot_vars: list, optional
545+
A list of the variables to plot. Deprecated, use output_variables instead.
546+
**kwargs
547+
Additional keyword arguments passed to
548+
:meth:`pybamm.QuickPlot.dynamic_plot`.
549+
For a list of all possible keyword arguments see :class:`pybamm.QuickPlot`.
544550
"""
545551

552+
if quick_plot_vars is not None:
553+
raise NotImplementedError(
554+
"'quick_plot_vars' has been deprecated. Use 'output_variables' instead."
555+
)
556+
546557
if self._solution is None:
547558
raise ValueError(
548559
"Model has not been solved, please solve the model before plotting."
549560
)
550561

551-
if quick_plot_vars is None:
552-
quick_plot_vars = self.quick_plot_vars
562+
if output_variables is None:
563+
output_variables = self.output_variables
553564

554565
self.quick_plot = pybamm.dynamic_plot(
555-
self._solution, output_variables=quick_plot_vars, testing=testing
566+
self._solution, output_variables=output_variables, **kwargs
556567
)
557568

558569
@property
@@ -625,12 +636,12 @@ def solver(self, solver):
625636
self._solver = solver.copy()
626637

627638
@property
628-
def quick_plot_vars(self):
629-
return self._quick_plot_vars
639+
def output_variables(self):
640+
return self._output_variables
630641

631-
@quick_plot_vars.setter
632-
def quick_plot_vars(self, quick_plot_vars):
633-
self._quick_plot_vars = copy.copy(quick_plot_vars)
642+
@output_variables.setter
643+
def output_variables(self, output_variables):
644+
self._output_variables = copy.copy(output_variables)
634645

635646
@property
636647
def solution(self):
@@ -644,7 +655,7 @@ def specs(
644655
var_pts=None,
645656
spatial_methods=None,
646657
solver=None,
647-
quick_plot_vars=None,
658+
output_variables=None,
648659
C_rate=None,
649660
):
650661
"Deprecated method for setting specs"

tests/unit/test_simulation.py

+4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ def test_plot(self):
297297
sim.solve(t_eval=t_eval)
298298
sim.plot(testing=True)
299299

300+
# test quick_plot_vars deprecation error
301+
with self.assertRaisesRegex(NotImplementedError, "'quick_plot_vars'"):
302+
sim.plot(quick_plot_vars=["var"])
303+
300304
def test_drive_cycle_data(self):
301305
model = pybamm.lithium_ion.SPM()
302306
param = model.default_parameter_values

0 commit comments

Comments
 (0)