Skip to content

Commit 8682c40

Browse files
committed
Fix QuadContourSet breaking change becoming Artist subclass
Solves GitHub issue #594.
1 parent 0c03058 commit 8682c40

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ https://semver.org/spec/v2.0.0.html
7272
Clang 16 and GCC 14 (PR [#595] by @fweimer-rh).
7373
- Apply basic cleanup of `_geoslib.pyx` source code (i.e. basic linting,
7474
removal of commented code, version update).
75+
- Fix breaking change from `matplotlib` 3.8 due to the promotion of
76+
`QuadContourSet` objects into `Artist` objects, which affected
77+
`Basemap.contour`, `Basemap.contourf` and `Basemap.nightshade`
78+
(solves issue [#594]).
7579

7680
### Removed
7781
- Attribute `__version__` in `mpl_toolkits.basemap.proj` module.
@@ -1077,6 +1081,8 @@ https://semver.org/spec/v2.0.0.html
10771081

10781082
[#595]:
10791083
https://github.com/matplotlib/basemap/pull/595
1084+
[#594]
1085+
https://github.com/matplotlib/basemap/issues/594
10801086
[#593]:
10811087
https://github.com/matplotlib/basemap/pull/593
10821088
[#592]:

packages/basemap/src/mpl_toolkits/basemap/__init__.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import numpy.ma as ma
3232

3333
import matplotlib as mpl
34+
from matplotlib.artist import Artist
3435
from matplotlib.collections import LineCollection
3536
from matplotlib.collections import PolyCollection
3637
from matplotlib.image import imread
@@ -3592,7 +3593,11 @@ def contour(self,x,y,data,*args,**kwargs):
35923593
# set axes limits to fit map region.
35933594
self.set_axes_limits(ax=ax)
35943595
# clip to map limbs
3595-
CS.collections,c = self._cliplimb(ax,CS.collections)
3596+
if isinstance(CS, Artist):
3597+
# Since MPL 3.8, `QuadContourSet` objects are `Artist` objects too.
3598+
CS, c = self._cliplimb(ax, CS)
3599+
else:
3600+
CS.collections, c = self._cliplimb(ax, CS.collections)
35963601
return CS
35973602

35983603
@_transform
@@ -3688,7 +3693,11 @@ def contourf(self,x,y,data,*args,**kwargs):
36883693
# set axes limits to fit map region.
36893694
self.set_axes_limits(ax=ax)
36903695
# clip to map limbs
3691-
CS.collections,c = self._cliplimb(ax,CS.collections)
3696+
if isinstance(CS, Artist):
3697+
# Since MPL 3.8, `QuadContourSet` objects are `Artist` objects too.
3698+
CS, c = self._cliplimb(ax, CS)
3699+
else:
3700+
CS.collections, c = self._cliplimb(ax, CS.collections)
36923701
return CS
36933702

36943703
@_transformuv
@@ -4733,12 +4742,18 @@ def nightshade(self,date,color="k",delta=0.25,alpha=0.5,ax=None,zorder=2):
47334742
# contour the day-night grid, coloring the night area
47344743
# with the specified color and transparency.
47354744
CS = self.contourf(x,y,daynight,1,colors=[color],alpha=alpha,ax=ax)
4736-
# set zorder on ContourSet collections show night shading
4737-
# is on top.
4738-
for c in CS.collections:
4739-
c.set_zorder(zorder)
4740-
# clip to map limbs
4741-
CS.collections,c = self._cliplimb(ax,CS.collections)
4745+
if isinstance(CS, Artist):
4746+
# Since MPL 3.8, `QuadContourSet` objects are `Artist` objects too.
4747+
CS.set_zorder(zorder)
4748+
# clip to map limbs
4749+
CS, c = self._cliplimb(ax, CS)
4750+
else:
4751+
# set zorder on ContourSet collections show night shading
4752+
# is on top.
4753+
for c in CS.collections:
4754+
c.set_zorder(zorder)
4755+
# clip to map limbs
4756+
CS.collections, c = self._cliplimb(ax, CS.collections)
47424757
return CS
47434758

47444759
def _check_ax(self):

0 commit comments

Comments
 (0)