diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 3caf386ef6..1d5d2873f9 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -65,6 +65,9 @@ This document explains the changes made to Iris for this release #. `@rcomer`_ modified :func:`~iris.plot.contourf` to skip the special handling for antialiasing when data values are too low for it to have an effect. This caused unexpected artifacts in some edge cases, as shown at :issue:`4086`. (:pull:`4150`) + +#. `@rcomer`_ modified :mod:`iris.quickplot` so that, if an axes is supplied, any + colourbar will appear below it, fixing :issue:`4126`. (:pull:`4136`) 💣 Incompatible Changes diff --git a/lib/iris/quickplot.py b/lib/iris/quickplot.py index 2eec514e9c..1b428693ec 100644 --- a/lib/iris/quickplot.py +++ b/lib/iris/quickplot.py @@ -72,7 +72,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, orientation="horizontal", drawedges=draw_edges, ax=axes ) has_known_units = not ( cube.units.is_unknown() or cube.units.is_no_unit() diff --git a/lib/iris/tests/test_quickplot.py b/lib/iris/tests/test_quickplot.py index 8abbf48a94..0144b5c535 100644 --- a/lib/iris/tests/test_quickplot.py +++ b/lib/iris/tests/test_quickplot.py @@ -247,5 +247,24 @@ def test_not_reference_time_units(self): self.check_graphic() +@tests.skip_data +@tests.skip_plot +class TestColorbar(tests.IrisTest): + def test_colorbar_location(self): + theta = _load_theta() + theta_slice = next( + theta.slices(["model_level_number", "grid_longitude"]) + ) + + fig1 = plt.figure() + plt.figure() + ax = fig1.add_subplot(1, 1, 1) + + result = qplt.contourf(theta_slice, axes=ax) + + # Colourbar should appear on same figure as ax, i.e. fig1. + self.assertIs(result.colorbar.ax.get_figure(), fig1) + + if __name__ == "__main__": tests.main()