From b022485615325530cb5488f98764cf8e13e359ae Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 20 Aug 2022 22:28:48 -0400 Subject: [PATCH 1/2] Fix Axes clearing with Matplotlib 3.6+ --- lib/cartopy/mpl/geoaxes.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/cartopy/mpl/geoaxes.py b/lib/cartopy/mpl/geoaxes.py index 5e59cc1ee..850fcf716 100644 --- a/lib/cartopy/mpl/geoaxes.py +++ b/lib/cartopy/mpl/geoaxes.py @@ -575,9 +575,8 @@ def _update_title_position(self, renderer): def __str__(self): return '< GeoAxes: %s >' % self.projection - def cla(self): - """Clear the current axes and adds boundary lines.""" - result = super().cla() + def __clear(self): + """Clear the current axes and add boundary lines.""" self.xaxis.set_visible(False) self.yaxis.set_visible(False) # Enable tight autoscaling. @@ -593,7 +592,18 @@ def cla(self): self.dataLim.intervalx = self.projection.x_limits self.dataLim.intervaly = self.projection.y_limits - return result + if mpl.__version__ >= '3.6': + def clear(self): + """Clear the current Axes and add boundary lines.""" + result = super().clear() + self.__clear() + return result + else: + def cla(self): + """Clear the current Axes and add boundary lines.""" + result = super().cla() + self.__clear() + return result def format_coord(self, x, y): """ From 7b0567f1b4c8c42bb00767b1b7c3bb4968040368 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 20 Aug 2022 23:42:15 -0400 Subject: [PATCH 2/2] Fix new deprecation warnings from Matplotlib 3.6 in tests --- lib/cartopy/tests/mpl/test_images.py | 3 +-- lib/cartopy/tests/mpl/test_pseudo_color.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/cartopy/tests/mpl/test_images.py b/lib/cartopy/tests/mpl/test_images.py index b424708c3..d04972aa7 100644 --- a/lib/cartopy/tests/mpl/test_images.py +++ b/lib/cartopy/tests/mpl/test_images.py @@ -9,7 +9,6 @@ import numpy as np import matplotlib.pyplot as plt -import matplotlib.cm as cm import matplotlib.colors as colors from PIL import Image import pytest @@ -143,7 +142,7 @@ def test_imshow_rgba(): # tests that the alpha of a RGBA array passed to imshow is set to 0 # instead of masked z = np.full((100, 100), 0.5) - cmap = cm.get_cmap() + cmap = plt.get_cmap() norm = colors.Normalize(vmin=0, vmax=1) z1 = cmap(norm(z)) plt_crs = ccrs.LambertAzimuthalEqualArea() diff --git a/lib/cartopy/tests/mpl/test_pseudo_color.py b/lib/cartopy/tests/mpl/test_pseudo_color.py index d4eb4abc3..da00681f9 100644 --- a/lib/cartopy/tests/mpl/test_pseudo_color.py +++ b/lib/cartopy/tests/mpl/test_pseudo_color.py @@ -92,7 +92,7 @@ def test_pcolormesh_datalim(): # Z with the same shape as X/Y to force the interpolation z = np.zeros(xs.shape) - ax = plt.subplot(2, 1, 1, projection=ccrs.PlateCarree()) + ax = plt.subplot(3, 1, 1, projection=ccrs.PlateCarree()) coll = ax.pcolormesh(xs, ys, z, shading='auto', transform=ccrs.PlateCarree()) @@ -104,7 +104,7 @@ def test_pcolormesh_datalim(): y = [-10, 10] xs, ys = np.meshgrid(x, y) - ax = plt.subplot(2, 1, 1, projection=ccrs.PlateCarree()) + ax = plt.subplot(3, 1, 2, projection=ccrs.PlateCarree()) coll = ax.pcolormesh(xs, ys, z, shading='auto', transform=ccrs.PlateCarree()) @@ -116,7 +116,7 @@ def test_pcolormesh_datalim(): y = [-10, 10] xs, ys = np.meshgrid(x, y) - ax = plt.subplot(2, 1, 1, projection=ccrs.Orthographic()) + ax = plt.subplot(3, 1, 3, projection=ccrs.Orthographic()) coll = ax.pcolormesh(xs, ys, z, shading='auto', transform=ccrs.PlateCarree())