From 0b569cdfad5e67f4aec3562bb26460020c7c7354 Mon Sep 17 00:00:00 2001 From: Ruth Comer <10599679+rcomer@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:44:52 +0100 Subject: [PATCH] Gallery: show colour bar stealing space from multiple axes (#5537) * Gallery: show colour bar stealing from multiple axes * use Iris' automatic axes replacement * update test data version * Link gallery page from whatsnew Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> --------- Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> --- .github/workflows/benchmarks_run.yml | 2 +- .github/workflows/ci-tests.yml | 2 +- .../gallery_code/meteorology/plot_COP_maps.py | 22 +++++-------------- docs/src/whatsnew/latest.rst | 4 ++++ lib/iris/tests/results/imagerepo.json | 2 +- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/.github/workflows/benchmarks_run.yml b/.github/workflows/benchmarks_run.yml index a39c531a77..02b913c6f0 100644 --- a/.github/workflows/benchmarks_run.yml +++ b/.github/workflows/benchmarks_run.yml @@ -29,7 +29,7 @@ jobs: env: IRIS_TEST_DATA_LOC_PATH: benchmarks IRIS_TEST_DATA_PATH: benchmarks/iris-test-data - IRIS_TEST_DATA_VERSION: "2.19" + IRIS_TEST_DATA_VERSION: "2.21" # Lets us manually bump the cache to rebuild ENV_CACHE_BUILD: "0" TEST_DATA_CACHE_BUILD: "2" diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 5c48966ce8..8d84d4e137 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -50,7 +50,7 @@ jobs: session: "tests" env: - IRIS_TEST_DATA_VERSION: "2.19" + IRIS_TEST_DATA_VERSION: "2.21" ENV_NAME: "ci-tests" steps: diff --git a/docs/gallery_code/meteorology/plot_COP_maps.py b/docs/gallery_code/meteorology/plot_COP_maps.py index 5e158346a9..529018ec8c 100644 --- a/docs/gallery_code/meteorology/plot_COP_maps.py +++ b/docs/gallery_code/meteorology/plot_COP_maps.py @@ -171,23 +171,13 @@ def main(): ) plt.gca().coastlines() - # Now add a colourbar who's leftmost point is the same as the leftmost - # point of the left hand plot and rightmost point is the rightmost - # point of the right hand plot. - - # Get the positions of the 2nd plot and the left position of the 1st plot. - left, bottom, width, height = ax_array[1].get_position().bounds - first_plot_left = ax_array[0].get_position().bounds[0] - - # The width of the colorbar should now be simple. - width = left - first_plot_left + width - - # Add axes to the figure, to place the colour bar. - colorbar_axes = fig.add_axes([first_plot_left, 0.18, width, 0.03]) - - # Add the colour bar. + # Now add a colour bar which spans the two plots. Here we pass Figure.axes + # which is a list of all (two) axes currently on the figure. Note that + # these are different to the contents of ax_array, because those were + # standard Matplotlib Axes that Iris automatically replaced with Cartopy + # GeoAxes. cbar = plt.colorbar( - contour_result, colorbar_axes, orientation="horizontal" + contour_result, ax=fig.axes, aspect=60, orientation="horizontal" ) # Label the colour bar and add ticks. diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 333cce6db9..c5cd961679 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -75,6 +75,10 @@ This document explains the changes made to Iris for this release #. `@trexfeathers`_ documented the intended use of warnings filtering with Iris. See :ref:`filtering-warnings`. (:pull:`5509`) +#. `@rcomer`_ updated the + :ref:`sphx_glr_generated_gallery_meteorology_plot_COP_maps.py` to show how + a colourbar may steal space from multiple axes. (:pull:`5537`) + 💼 Internal =========== diff --git a/lib/iris/tests/results/imagerepo.json b/lib/iris/tests/results/imagerepo.json index 2313c25270..2a6e2c4dbc 100644 --- a/lib/iris/tests/results/imagerepo.json +++ b/lib/iris/tests/results/imagerepo.json @@ -1,6 +1,6 @@ { "gallery_tests.test_plot_COP_1d.0": "aefec91c3601249cc9b3336dc4c8cdb31a64c6d997b3c0eccb5932d285e42f33", - "gallery_tests.test_plot_COP_maps.0": "ea9130db95668524913e6ac168991f0d956e917ec76396b96a853dcf94696935", + "gallery_tests.test_plot_COP_maps.0": "ea91789995668566913e43474adb6a917e8d947c4b46957ec6716a91958e6f81", "gallery_tests.test_plot_SOI_filtering.0": "fa56f295c5e0694a3c17a58d95e8da536233da99984c5af4c6739b4a9a444eb4", "gallery_tests.test_plot_TEC.0": "e5a761b69a589a4bc46f9e48c65c6631ce61d1ce3982c13739b33193c0ee3f8c", "gallery_tests.test_plot_anomaly_log_colouring.0": "ec4464e384a39b13931a9b1c85696da968d5e6e63e26847bdbd399938d3c5a4c",