Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca058ac

Browse files
committed
Merge branch 'bugfix-mpl38-upgrade' into develop
2 parents 8921657 + b0724a2 commit ca058ac

File tree

4 files changed

+75
-9
lines changed

4 files changed

+75
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ https://semver.org/spec/v2.0.0.html
3636
- Upgrade `pillow` upper limit to 10.2.0.
3737
- Update library dependencies:
3838
- Upgrade upper limit for `numpy` to 1.27.0.
39+
- Upgrade upper limit for `matplotlib` to 3.9.0.
3940
- Downgrade upper limit for `pyproj` to 2.2.0 for Python 2.7.
4041
- Set dependency on `packaging` as replacement for `distutils`.
4142
- Update build dependencies:
@@ -71,6 +72,10 @@ https://semver.org/spec/v2.0.0.html
7172
Clang 16 and GCC 14 (PR [#595] by @fweimer-rh).
7273
- Apply basic cleanup of `_geoslib.pyx` source code (i.e. basic linting,
7374
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], thanks to @qianwu2 and @rcomer).
7479

7580
### Removed
7681
- Attribute `__version__` in `mpl_toolkits.basemap.proj` module.
@@ -1076,6 +1081,8 @@ https://semver.org/spec/v2.0.0.html
10761081

10771082
[#595]:
10781083
https://github.com/matplotlib/basemap/pull/595
1084+
[#594]:
1085+
https://github.com/matplotlib/basemap/issues/594
10791086
[#593]:
10801087
https://github.com/matplotlib/basemap/pull/593
10811088
[#592]:

packages/basemap/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ matplotlib >= 1.5, < 3.0; python_version == "2.7"
1818
matplotlib >= 1.5, < 2.0; python_version == "3.2"
1919
matplotlib >= 1.5, < 2.0; python_version == "3.3"
2020
matplotlib >= 1.5, < 3.0; python_version == "3.4"
21-
matplotlib >= 1.5, < 3.8; python_version >= "3.5"
21+
matplotlib >= 1.5, < 3.9; python_version >= "3.5"
2222

2323
pyproj >= 1.9.3, < 2.1.0; python_version == "2.6"
2424
pyproj >= 1.9.3, < 2.2.0; python_version == "2.7"

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

Lines changed: 23 additions & 8 deletions
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):

packages/basemap/test/mpl_toolkits/basemap/test_Basemap.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Import test for the :mod:`mpl_toolkits.basemap.Basemap` class."""
22

3+
import datetime as dt
34
try:
45
import unittest2 as unittest
56
except ImportError:
@@ -9,6 +10,7 @@
910
import matplotlib as mpl
1011
import matplotlib.pyplot as plt
1112
from matplotlib.collections import LineCollection
13+
from matplotlib.contour import QuadContourSet
1214
from matplotlib.image import AxesImage
1315
from matplotlib.patches import Polygon
1416
from mpl_toolkits.basemap import Basemap
@@ -204,6 +206,48 @@ def test_shadedrelief_with_custom_axes(self):
204206
_, axs = plt.subplots()
205207
self.test_shadedrelief(axs=axs, axslen0=10)
206208

209+
def _test_generic_contour_function(self, function):
210+
"""Generic test for the `contour` and `contourf` methods."""
211+
212+
bmap = Basemap(projection="ortho", lat_0=45, lon_0=-100, resolution=None)
213+
214+
# Create a regular lat/lon grid.
215+
nlats = 73
216+
nlons = 145
217+
delta = 2 * np.pi / (nlons - 1)
218+
indx = np.indices((nlats, nlons))
219+
lats = (0.5 * np.pi - delta * indx[0, :, :])
220+
lons = (delta * indx[1, :, :])
221+
222+
# Create some data the regular lat/lon grid.
223+
mean = 0.50 * np.cos(2 * lats) * ((np.sin(2 * lats))**2 + 2)
224+
wave = 0.75 * np.cos(4 * lons) * np.sin(2 * lats)**8
225+
data = mean + wave
226+
227+
# Compute native map projection coordinates of lat/lon grid.
228+
x, y = bmap(np.degrees(lons), np.degrees(lats))
229+
230+
# Contour data over the map and check output.
231+
cset = getattr(bmap, function)(x, y, data, 15)
232+
self.assertIsInstance(cset, QuadContourSet)
233+
234+
def test_contour(self):
235+
"""Test drawing contours on a map."""
236+
237+
self._test_generic_contour_function("contour")
238+
239+
def test_contourf(self):
240+
"""Test drawing filled contours on a map."""
241+
242+
self._test_generic_contour_function("contourf")
243+
244+
def test_nightshade(self):
245+
"""Test drawing the day/night terminator and night shade on a map."""
246+
247+
bmap = Basemap(projection="mill", lon_0=180)
248+
cset = bmap.nightshade(date=dt.datetime(1970, 1, 1))
249+
self.assertIsInstance(cset, QuadContourSet)
250+
207251

208252
class TestMplToolkitsBasemapBasemapCall(unittest.TestCase):
209253
"""Unittest class for :meth:`mpl_toolkits.basemap.Basemap.__call__`."""

0 commit comments

Comments
 (0)