From f6154556b257e878f6ea2e063f74332963af35d1 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Wed, 4 Oct 2023 17:50:49 +0100 Subject: [PATCH 1/2] Bump minimum Matplotlib version to 3.5 --- .github/workflows/ci-testing.yml | 2 +- INSTALL | 2 +- lib/cartopy/mpl/__init__.py | 4 ++-- lib/cartopy/tests/mpl/test_crs.py | 6 +++--- lib/cartopy/tests/mpl/test_mpl_integration.py | 9 +++------ 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index f9993de9d..82140eae6 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -33,7 +33,7 @@ jobs: if: matrix.python-version == '3.9' && matrix.os == 'ubuntu-latest' id: minimum-packages run: | - pip install cython==0.29.24 matplotlib==3.4.3 numpy==1.21 owslib==0.24.1 pyproj==3.1 scipy==1.6.3 shapely==1.7.1 + pip install cython==0.29.24 matplotlib==3.5.3 numpy==1.21 owslib==0.24.1 pyproj==3.1 scipy==1.6.3 shapely==1.7.1 - name: Coverage packages id: coverage diff --git a/INSTALL b/INSTALL index 0fed352a1..49e93adf4 100644 --- a/INSTALL +++ b/INSTALL @@ -62,7 +62,7 @@ Further information about the required dependencies can be found here: **Python** 3.9 or later (https://www.python.org/) Python 2 support was removed in v0.19. -**Matplotlib** 3.4 or later (https://matplotlib.org/) +**Matplotlib** 3.5 or later (https://matplotlib.org/) Python package for 2D plotting. Python package required for any graphical capabilities. diff --git a/lib/cartopy/mpl/__init__.py b/lib/cartopy/mpl/__init__.py index 75bcce3a9..1f8a0e7c5 100644 --- a/lib/cartopy/mpl/__init__.py +++ b/lib/cartopy/mpl/__init__.py @@ -9,8 +9,8 @@ _MPL_VERSION = packaging.version.parse(matplotlib.__version__) -_MPL_34 = _MPL_VERSION.release[:2] >= (3, 4) _MPL_35 = _MPL_VERSION.release[:2] >= (3, 5) +_MPL_36 = _MPL_VERSION.release[:2] >= (3, 6) _MPL_38 = _MPL_VERSION.release[:2] >= (3, 8) -assert _MPL_34, 'Cartopy is only supported with Matplotlib 3.4 or greater.' +assert _MPL_35, 'Cartopy is only supported with Matplotlib 3.5 or greater.' diff --git a/lib/cartopy/tests/mpl/test_crs.py b/lib/cartopy/tests/mpl/test_crs.py index c37036662..d7a4baba7 100644 --- a/lib/cartopy/tests/mpl/test_crs.py +++ b/lib/cartopy/tests/mpl/test_crs.py @@ -8,12 +8,12 @@ import pytest import cartopy.crs as ccrs -from cartopy.mpl import _MPL_35 +from cartopy.mpl import _MPL_36 @pytest.mark.natural_earth @pytest.mark.mpl_image_compare( - filename="igh_land.png", tolerance=0.5 if _MPL_35 else 3.6) + filename="igh_land.png", tolerance=0.5 if _MPL_36 else 3.6) def test_igh_land(): crs = ccrs.InterruptedGoodeHomolosine(emphasis="land") ax = plt.axes(projection=crs) @@ -24,7 +24,7 @@ def test_igh_land(): @pytest.mark.natural_earth @pytest.mark.mpl_image_compare(filename="igh_ocean.png", - tolerance=0.5 if _MPL_35 else 4.5) + tolerance=0.5 if _MPL_36 else 4.5) def test_igh_ocean(): crs = ccrs.InterruptedGoodeHomolosine( central_longitude=-160, emphasis="ocean" diff --git a/lib/cartopy/tests/mpl/test_mpl_integration.py b/lib/cartopy/tests/mpl/test_mpl_integration.py index deba9cf49..cc4e1ca5b 100644 --- a/lib/cartopy/tests/mpl/test_mpl_integration.py +++ b/lib/cartopy/tests/mpl/test_mpl_integration.py @@ -12,7 +12,7 @@ import pytest import cartopy.crs as ccrs -from cartopy.mpl import _MPL_35, _MPL_38 +from cartopy.mpl import _MPL_38 @pytest.mark.natural_earth @@ -196,8 +196,7 @@ def test_simple_global(): id='ObliqueMercator_rotated', ), ]) -@pytest.mark.mpl_image_compare( - tolerance=0.5 if _MPL_35 else 0.97, style='mpl20') +@pytest.mark.mpl_image_compare(style='mpl20') def test_global_map(proj): if isinstance(proj, tuple): proj, kwargs = proj @@ -957,9 +956,7 @@ def test_barbs_1d_transformed(): @pytest.mark.natural_earth -@pytest.mark.mpl_image_compare( - filename='streamplot.png', style='mpl20', - tolerance=0.5 if _MPL_35 else 9.77) +@pytest.mark.mpl_image_compare(filename='streamplot.png', style='mpl20') def test_streamplot(): x = np.arange(-60, 42.5, 2.5) y = np.arange(30, 72.5, 2.5) From 178684c881c2d6265b42a7dc6f91b9bc274fb861 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Wed, 4 Oct 2023 18:28:56 +0100 Subject: [PATCH 2/2] Fix constrained layout padding pre mpl v3.6 --- lib/cartopy/tests/mpl/test_gridliner.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/cartopy/tests/mpl/test_gridliner.py b/lib/cartopy/tests/mpl/test_gridliner.py index 92884cf36..474820b54 100644 --- a/lib/cartopy/tests/mpl/test_gridliner.py +++ b/lib/cartopy/tests/mpl/test_gridliner.py @@ -14,6 +14,7 @@ from shapely.geos import geos_version import cartopy.crs as ccrs +from cartopy.mpl import _MPL_36 from cartopy.mpl.geoaxes import GeoAxes from cartopy.mpl.gridliner import (LATITUDE_FORMATTER, LONGITUDE_FORMATTER, Gridliner, classic_formatter, @@ -497,7 +498,10 @@ def test_gridliner_title_adjust(): plt.rcParams['axes.titley'] = None fig = plt.figure(layout='constrained') - fig.get_layout_engine().set(h_pad=1/8) + if _MPL_36: + fig.get_layout_engine().set(h_pad=1/8) + else: + fig.set_constrained_layout_pads(h_pad=1/8) for n, proj in enumerate(projs, 1): ax = fig.add_subplot(2, 2, n, projection=proj) ax.coastlines()