Skip to content
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
8 changes: 7 additions & 1 deletion docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -136,6 +136,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`)

#. `@rcomer`_ and `@bjlittle`_ (reviewer) modified :func:`iris.util.mask_cube` so it
either works in place or returns a new cube (:issue:`3717`, :pull:`4889`)

Expand Down Expand Up @@ -279,6 +284,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
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/quickplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _label(cube, mode, result=None, ndims=2, coords=None, axes=None):
if result is not None:
draw_edges = mode == iris.coords.POINT_MODE
bar = plt.colorbar(
result, orientation="horizontal", drawedges=draw_edges
result, ax=axes, orientation="horizontal", drawedges=draw_edges
)
has_known_units = not (
cube.units.is_unknown() or cube.units.is_no_unit()
Expand Down
34 changes: 34 additions & 0 deletions lib/iris/tests/test_quickplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()