From a1e5b321f39fb5fde9d4512d8f7e4d89ead212a4 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Fri, 14 May 2021 20:42:07 +0100 Subject: [PATCH 1/2] quickplot: locate colourbar with any supplied axes --- docs/src/whatsnew/latest.rst | 3 +++ lib/iris/quickplot.py | 2 +- lib/iris/tests/test_quickplot.py | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) 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..405897ab20 100644 --- a/lib/iris/tests/test_quickplot.py +++ b/lib/iris/tests/test_quickplot.py @@ -247,5 +247,23 @@ def test_not_reference_time_units(self): self.check_graphic() +@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() From a7ef6971c5693fc9efc311739cfeaa52062d4005 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Fri, 14 May 2021 20:53:05 +0100 Subject: [PATCH 2/2] add skip_data decorator --- lib/iris/tests/test_quickplot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/iris/tests/test_quickplot.py b/lib/iris/tests/test_quickplot.py index 405897ab20..0144b5c535 100644 --- a/lib/iris/tests/test_quickplot.py +++ b/lib/iris/tests/test_quickplot.py @@ -247,6 +247,7 @@ 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):