Skip to content

Commit

Permalink
Merge pull request #2071 from QuLogic/fix-mpl36
Browse files Browse the repository at this point in the history
Fix Axes clearing with Matplotlib 3.6+
  • Loading branch information
greglucas authored Aug 30, 2022
2 parents 357bd6b + 7b0567f commit 2ef404b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
18 changes: 14 additions & 4 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
"""
Expand Down
3 changes: 1 addition & 2 deletions lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions lib/cartopy/tests/mpl/test_pseudo_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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())

Expand All @@ -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())

Expand Down

0 comments on commit 2ef404b

Please sign in to comment.