diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 3c6391d0ba..61b4f02ffb 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -25,7 +25,7 @@ This document explains the changes made to Iris for this release 📢 Announcements ================ -#. N/A +#. Welcome to `@krikru`_ who made their first contribution to Iris 🎉 ✨ Features @@ -132,6 +132,11 @@ This document explains the changes made to Iris for this release array type. This prevents masks being lost in some cases and therefore resolves :issue:`2987`. (:pull:`3790`) +#. `@krikru`_ and `@rcomer`_ updated :mod:`iris.quickplot` such that the + colorbar is added to the correct ``axes`` when specified as a keyword + argument to a plotting routine. Otherwise, by default the colorbar will be + added to the current axes of the current figure. (:pull:`4894`) + 💣 Incompatible Changes ======================= @@ -272,6 +277,7 @@ This document explains the changes made to Iris for this release core dev names are automatically included by the common_links.inc: .. _@evertrol: https://github.com/evertrol +.. _@krikru: https://github.com/krikru .. comment diff --git a/lib/iris/tests/test_quickplot.py b/lib/iris/tests/test_quickplot.py index dec71a99ac..06f170c666 100644 --- a/lib/iris/tests/test_quickplot.py +++ b/lib/iris/tests/test_quickplot.py @@ -247,5 +247,39 @@ def test_not_reference_time_units(self): self.check_graphic() +@tests.skip_data +@tests.skip_plot +class TestSubplotColorbar(tests.IrisTest): + def setUp(self): + theta = _load_theta() + coords = ["model_level_number", "grid_longitude"] + self.data = next(theta.slices(coords)) + spec = (1, 1, 1) + self.figure1 = plt.figure() + self.axes1 = self.figure1.add_subplot(*spec) + self.figure2 = plt.figure() + self.axes2 = self.figure2.add_subplot(*spec) + + def _check(self, mappable, figure, axes): + self.assertIs(mappable.axes, axes) + self.assertIs(mappable.colorbar.mappable, mappable) + self.assertIs(mappable.colorbar.ax.get_figure(), figure) + + def test_with_axes1(self): + # plot using the first figure subplot axes (explicit) + mappable = qplt.contourf(self.data, axes=self.axes1) + self._check(mappable, self.figure1, self.axes1) + + def test_with_axes2(self): + # plot using the second figure subplot axes (explicit) + mappable = qplt.contourf(self.data, axes=self.axes2) + self._check(mappable, self.figure2, self.axes2) + + def test_without_axes__default(self): + # plot using the second/last figure subplot axes (default) + mappable = qplt.contourf(self.data) + self._check(mappable, self.figure2, self.axes2) + + if __name__ == "__main__": tests.main()