diff --git a/CHANGELOG.md b/CHANGELOG.md index 230344efbf..4061ec3f63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ -# [Unreleased](https://github.com/pybamm-team/PyBaMM) +# [v0.2.1](https://github.com/pybamm-team/PyBaMM/tree/v0.2.1) - 2020-03-31 + +New expression tree node types, models, parameter sets and solvers, as well as general bug fixes and new examples. ## Features @@ -26,6 +28,7 @@ ## Bug fixes +- Fixed tight layout for QuickPlot in jupyter notebooks ([#930](https://github.com/pybamm-team/PyBaMM/pull/930)) - Fixed bug raised if function returns a scalar ([#919](https://github.com/pybamm-team/PyBaMM/pull/919)) - Fixed event handling in `ScipySolver` ([#905](https://github.com/pybamm-team/PyBaMM/pull/905)) - Made input handling clearer in solvers ([#905](https://github.com/pybamm-team/PyBaMM/pull/905)) diff --git a/docs/conf.py b/docs/conf.py index e7cd1274e8..d4a743192f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ # The short X.Y version version = "0.2" # The full version, including alpha/beta/rc tags -release = "0.2.0" +release = "0.2.1" # -- General configuration --------------------------------------------------- diff --git a/pybamm/__init__.py b/pybamm/__init__.py index f3240dc0c1..9caa190c1e 100644 --- a/pybamm/__init__.py +++ b/pybamm/__init__.py @@ -218,7 +218,7 @@ def version(formatted=False): # other # from .processed_variable import ProcessedVariable -from .quick_plot import QuickPlot, ax_min, ax_max +from .quick_plot import QuickPlot, dynamic_plot, ax_min, ax_max from .simulation import Simulation, load_sim, is_notebook diff --git a/pybamm/quick_plot.py b/pybamm/quick_plot.py index 667318ad95..7f569840d9 100644 --- a/pybamm/quick_plot.py +++ b/pybamm/quick_plot.py @@ -3,7 +3,6 @@ # import numpy as np import pybamm -import warnings from collections import defaultdict @@ -45,6 +44,24 @@ def split_long_string(title, max_words=4): return first_line + "\n" + second_line +def dynamic_plot(*args, **kwargs): + """ + Creates a :class:`pybamm.QuickPlot` object (with arguments 'args' and keyword + arguments 'kwargs') and then calls :meth:`pybamm.QuickPlot.dynamic_plot`. + The key-word argument 'testing' is passed to the 'dynamic_plot' method, not the + `QuickPlot' class. + + Returns + ------- + plot : :class:`pybamm.QuickPlot` + The 'QuickPlot' object that was created + """ + kwargs_for_class = {k: v for k, v in kwargs.items() if k != "testing"} + plot = pybamm.QuickPlot(*args, **kwargs_for_class) + plot.dynamic_plot(kwargs.get("testing", False)) + return plot + + class QuickPlot(object): """ Generates a quick plot of a subset of key outputs of the model so that the model @@ -615,6 +632,10 @@ def plot(self, t): if len(solution_handles) > 0: self.fig.legend(solution_handles, self.labels, loc="lower right") + # Fix layout + bottom = 0.05 + 0.03 * max((len(self.labels) - 2), 0) + self.gridspec.tight_layout(self.fig, rect=[0, bottom, 1, 1]) + def dynamic_plot(self, testing=False, step=None): """ Generate a dynamic plot with a slider to control the time. @@ -651,12 +672,6 @@ def dynamic_plot(self, testing=False, step=None): ) self.slider.on_changed(self.slider_update) - # ignore the warning about tight layout - warnings.simplefilter("ignore") - bottom = 0.05 + 0.03 * max((len(self.labels) - 2), 0) - self.gridspec.tight_layout(self.fig, rect=[0, bottom, 1, 1]) - warnings.simplefilter("always") - if not testing: # pragma: no cover plt.show() diff --git a/pybamm/simulation.py b/pybamm/simulation.py index 6e85bf8566..72874b7dee 100644 --- a/pybamm/simulation.py +++ b/pybamm/simulation.py @@ -46,13 +46,12 @@ class Simulation: ---------- model : :class:`pybamm.BaseModel` The model to be simulated - experiment : : class:`pybamm.Experiment` (optional) + experiment : :class:`pybamm.Experiment` (optional) The experimental conditions under which to solve the model geometry: :class:`pybamm.Geometry` (optional) The geometry upon which to solve the model - parameter_values: dict (optional) - A dictionary of parameters and their corresponding numerical - values + parameter_values: :class:`pybamm.ParameterValues` (optional) + Parameters and their corresponding numerical values. submesh_types: dict (optional) A dictionary of the types of submesh to use on each subdomain var_pts: dict (optional) @@ -533,9 +532,9 @@ def plot(self, quick_plot_vars=None, testing=False): if quick_plot_vars is None: quick_plot_vars = self.quick_plot_vars - plot = pybamm.QuickPlot(self._solution, output_variables=quick_plot_vars) - - plot.dynamic_plot(testing=testing) + self.quick_plot = pybamm.dynamic_plot( + self._solution, output_variables=quick_plot_vars, testing=testing + ) @property def model(self): diff --git a/pybamm/solvers/solution.py b/pybamm/solvers/solution.py index 0adec1a630..8734ad8a54 100644 --- a/pybamm/solvers/solution.py +++ b/pybamm/solvers/solution.py @@ -233,10 +233,10 @@ def save_data(self, filename, variables=None, to_format="pickle"): savemat(filename, data) elif to_format == "csv": for name, var in data.items(): - if var.ndim == 2: + if var.ndim >= 2: raise ValueError( - "only 1D variables can be saved to csv, but '{}' is 2D".format( - name + "only 0D variables can be saved to csv, but '{}' is {}D".format( + name, var.ndim - 1 ) ) df = pd.DataFrame(data) diff --git a/pybamm/version b/pybamm/version index 6e91a93f84..bfa665d579 100644 --- a/pybamm/version +++ b/pybamm/version @@ -1 +1 @@ -0, 2, 0 +0, 2, 1 diff --git a/tests/unit/test_solvers/test_solution.py b/tests/unit/test_solvers/test_solution.py index 0fa8a33013..c1615e2f8d 100644 --- a/tests/unit/test_solvers/test_solution.py +++ b/tests/unit/test_solvers/test_solution.py @@ -125,7 +125,7 @@ def test_save(self): # to csv with self.assertRaisesRegex( - ValueError, "only 1D variables can be saved to csv" + ValueError, "only 0D variables can be saved to csv" ): solution.save_data("test.csv", to_format="csv") # only save "c" and "2c"