Skip to content

Commit

Permalink
Gallery: show colour bar stealing space from multiple axes (#5537)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: Martin Yeo <[email protected]>
  • Loading branch information
rcomer and trexfeathers authored Oct 10, 2023
1 parent ee6b225 commit 0b569cd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 6 additions & 16 deletions docs/gallery_code/meteorology/plot_COP_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/results/imagerepo.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0b569cd

Please sign in to comment.