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

Skip to content

Commit b0724a2

Browse files
committed
Add tests covering bugfix for MPL 3.8
1 parent 8682c40 commit b0724a2

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ https://semver.org/spec/v2.0.0.html
7575
- Fix breaking change from `matplotlib` 3.8 due to the promotion of
7676
`QuadContourSet` objects into `Artist` objects, which affected
7777
`Basemap.contour`, `Basemap.contourf` and `Basemap.nightshade`
78-
(solves issue [#594]).
78+
(solves issue [#594], thanks to @qianwu2 and @rcomer).
7979

8080
### Removed
8181
- Attribute `__version__` in `mpl_toolkits.basemap.proj` module.
@@ -1081,7 +1081,7 @@ https://semver.org/spec/v2.0.0.html
10811081

10821082
[#595]:
10831083
https://github.com/matplotlib/basemap/pull/595
1084-
[#594]
1084+
[#594]:
10851085
https://github.com/matplotlib/basemap/issues/594
10861086
[#593]:
10871087
https://github.com/matplotlib/basemap/pull/593

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)