Skip to content

Commit 8a73b48

Browse files
committed
Use contourpy for quad contour calculations
1 parent 07f8987 commit 8a73b48

File tree

13 files changed

+251
-2836
lines changed

13 files changed

+251
-2836
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ jobs:
161161
162162
# Install dependencies from PyPI.
163163
python -m pip install --upgrade $PRE \
164-
cycler fonttools kiwisolver numpy packaging pillow pyparsing \
164+
contourpy>=1 cycler fonttools kiwisolver numpy packaging pillow pyparsing \
165165
python-dateutil setuptools-scm \
166166
-r requirements/testing/all.txt \
167167
${{ matrix.extra-requirements }}

environment.yml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,20 +1434,19 @@ def _process_args(self, *args, corner_mask=None, **kwargs):
14341434
self._mins = args[0]._mins
14351435
self._maxs = args[0]._maxs
14361436
else:
1437-
import matplotlib._contour as _contour
1437+
import contourpy
14381438

14391439
if corner_mask is None:
14401440
corner_mask = mpl.rcParams['contour.corner_mask']
14411441
self._corner_mask = corner_mask
14421442

14431443
x, y, z = self._contour_args(args, kwargs)
14441444

1445-
_mask = ma.getmask(z)
1446-
if _mask is ma.nomask or not _mask.any():
1447-
_mask = None
1448-
1449-
contour_generator = _contour.QuadContourGenerator(
1450-
x, y, z.filled(), _mask, self._corner_mask, self.nchunk)
1445+
contour_generator = contourpy.contour_generator(
1446+
x, y, z, name="mpl2014", corner_mask=self._corner_mask,
1447+
line_type=contourpy.LineType.SeparateCode,
1448+
fill_type=contourpy.FillType.OuterCode,
1449+
chunk_size=self.nchunk)
14511450

14521451
t = self.get_transform()
14531452

Binary file not shown.

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

Lines changed: 241 additions & 231 deletions
Loading

lib/matplotlib/tests/test_contour.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -243,33 +243,6 @@ def test_contourf_symmetric_locator():
243243
assert_array_almost_equal(cs.levels, np.linspace(-12, 12, 5))
244244

245245

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

requirements/testing/minver.txt

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,6 @@ def get_extensions(self):
398398
"win32": ["ole32", "shell32", "user32"],
399399
}.get(sys.platform, [])))
400400
yield ext
401-
# contour
402-
ext = Extension(
403-
"matplotlib._contour", [
404-
"src/_contour.cpp",
405-
"src/_contour_wrapper.cpp",
406-
"src/py_converters.cpp",
407-
])
408-
add_numpy_flags(ext)
409-
add_libagg_flags(ext)
410-
yield ext
411401
# ft2font
412402
ext = Extension(
413403
"matplotlib.ft2font", [

0 commit comments

Comments
 (0)