Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump minimum Matplotlib version to 3.5 #2258

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions lib/cartopy/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
6 changes: 3 additions & 3 deletions lib/cartopy/tests/mpl/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI fails here if the tolerance is set to 0.5 with mpl 3.5.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused by this because it looks like the tolerances were set at #2058, when mpl 3.5.2 would have been the newest version 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't read too much into that. Maybe the image was made with a main checkout at the time or something? Our tests are often brittle to these things, so this seems fine to me to bump one version chalking it up to we didn't know exactly which minimum version was needed.

Maybe we should think about testing with all versions of Matplotlib that we support though rather than only the newest and oldest.

def test_igh_land():
crs = ccrs.InterruptedGoodeHomolosine(emphasis="land")
ax = plt.axes(projection=crs)
Expand All @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Copy link
Member Author

@rcomer rcomer Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation note on set_constrained_layout_pads suggests that the above should work from v3.6, but I have not actually tested.
https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.set_constrained_layout_pads

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()
Expand Down
9 changes: 3 additions & 6 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading