Skip to content

Commit 313dd2a

Browse files
committed
Use contourpy for quad contour calculations
1 parent 3a994d2 commit 313dd2a

File tree

13 files changed

+251
-2836
lines changed

13 files changed

+251
-2836
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ jobs:
158158
159159
# Install dependencies from PyPI.
160160
python -m pip install --upgrade $PRE \
161-
cycler fonttools kiwisolver numpy packaging pillow pyparsing \
161+
contourpy>=1 cycler fonttools kiwisolver numpy packaging pillow pyparsing \
162162
python-dateutil setuptools-scm \
163163
-r requirements/testing/all.txt \
164164
${{ matrix.extra-requirements }}

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ channels:
99
- conda-forge
1010
dependencies:
1111
- cairocffi
12+
- contourpy>=1
1213
- cycler>=0.10.0
1314
- fonttools>=4.22.0
1415
- kiwisolver>=1.0.1

lib/matplotlib/contour.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1429,20 +1429,19 @@ def _process_args(self, *args, corner_mask=None, **kwargs):
14291429
self._mins = args[0]._mins
14301430
self._maxs = args[0]._maxs
14311431
else:
1432-
import matplotlib._contour as _contour
1432+
import contourpy
14331433

14341434
if corner_mask is None:
14351435
corner_mask = mpl.rcParams['contour.corner_mask']
14361436
self._corner_mask = corner_mask
14371437

14381438
x, y, z = self._contour_args(args, kwargs)
14391439

1440-
_mask = ma.getmask(z)
1441-
if _mask is ma.nomask or not _mask.any():
1442-
_mask = None
1443-
1444-
contour_generator = _contour.QuadContourGenerator(
1445-
x, y, z.filled(), _mask, self._corner_mask, self.nchunk)
1440+
contour_generator = contourpy.contour_generator(
1441+
x, y, z, name="mpl2014", corner_mask=self._corner_mask,
1442+
line_type=contourpy.LineType.SeparateCode,
1443+
fill_type=contourpy.FillType.OuterCode,
1444+
chunk_size=self.nchunk)
14461445

14471446
t = self.get_transform()
14481447

Binary file not shown.

lib/matplotlib/tests/baseline_images/test_patheffects/patheffect2.svg

+241-231
Loading

lib/matplotlib/tests/test_contour.py

-27
Original file line numberDiff line numberDiff line change
@@ -244,33 +244,6 @@ def test_contourf_symmetric_locator():
244244
assert_array_almost_equal(cs.levels, np.linspace(-12, 12, 5))
245245

246246

247-
@pytest.mark.parametrize("args, cls, message", [
248-
((), TypeError,
249-
'function takes exactly 6 arguments (0 given)'),
250-
((1, 2, 3, 4, 5, 6), ValueError,
251-
'Expected 2-dimensional array, got 0'),
252-
(([[0]], [[0]], [[]], None, True, 0), ValueError,
253-
'x, y and z must all be 2D arrays with the same dimensions'),
254-
(([[0]], [[0]], [[0]], None, True, 0), ValueError,
255-
'x, y and z must all be at least 2x2 arrays'),
256-
((*[np.arange(4).reshape((2, 2))] * 3, [[0]], True, 0), ValueError,
257-
'If mask is set it must be a 2D array with the same dimensions as x.'),
258-
])
259-
def test_internal_cpp_api(args, cls, message): # Github issue 8197.
260-
from matplotlib import _contour # noqa: ensure lazy-loaded module *is* loaded.
261-
with pytest.raises(cls, match=re.escape(message)):
262-
mpl._contour.QuadContourGenerator(*args)
263-
264-
265-
def test_internal_cpp_api_2():
266-
from matplotlib import _contour # noqa: ensure lazy-loaded module *is* loaded.
267-
arr = [[0, 1], [2, 3]]
268-
qcg = mpl._contour.QuadContourGenerator(arr, arr, arr, None, True, 0)
269-
with pytest.raises(
270-
ValueError, match=r'filled contour levels must be increasing'):
271-
qcg.create_filled_contour(1, 0)
272-
273-
274247
def test_circular_contour_warning():
275248
# Check that almost circular contours don't throw a warning
276249
x, y = np.meshgrid(np.linspace(-2, 2, 4), np.linspace(-2, 2, 4))

requirements/testing/minver.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Extra pip requirements for the minimum-version CI run
22

3+
contourpy>=1
34
cycler==0.10
45
kiwisolver==1.0.1
56
numpy==1.19.0

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ def make_release_tree(self, base_dir, files):
306306
"setuptools_scm_git_archive",
307307
],
308308
install_requires=[
309+
"contourpy>=1",
309310
"cycler>=0.10",
310311
"fonttools>=4.22.0",
311312
"kiwisolver>=1.0.1",

setupext.py

-10
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,6 @@ def get_extensions(self):
390390
"win32": ["ole32", "shell32", "user32"],
391391
}.get(sys.platform, [])))
392392
yield ext
393-
# contour
394-
ext = Extension(
395-
"matplotlib._contour", [
396-
"src/_contour.cpp",
397-
"src/_contour_wrapper.cpp",
398-
"src/py_converters.cpp",
399-
])
400-
add_numpy_flags(ext)
401-
add_libagg_flags(ext)
402-
yield ext
403393
# ft2font
404394
ext = Extension(
405395
"matplotlib.ft2font", [

0 commit comments

Comments
 (0)