From 090cc967b805fb7afdc920e4e24d6e48f8775858 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 12 May 2019 21:43:22 +0200 Subject: [PATCH] Deprecate Path helpers in bezier.py ... in favor of the corresponding ones in path.py. (Strictly speaking, `make_path_regular` is closed to `cleaned(remove_nans=False)` but in practice `cleaned()` works equally well.) --- doc/api/next_api_changes/deprecations.rst | 10 ++++++++++ lib/matplotlib/bezier.py | 3 +++ lib/matplotlib/patches.py | 16 ++++++---------- lib/matplotlib/tests/test_artist.py | 5 +---- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/doc/api/next_api_changes/deprecations.rst b/doc/api/next_api_changes/deprecations.rst index 632a0ac25874..5b3d58b8b416 100644 --- a/doc/api/next_api_changes/deprecations.rst +++ b/doc/api/next_api_changes/deprecations.rst @@ -376,3 +376,13 @@ NavigationToolbar2QT.parent This attribute is deprecated. In order to access the parent window, use ``toolbar.canvas.parent()``. Once the deprecation period is elapsed, it will also be accessible as ``toolbar.parent()``. + +Path helpers in :mod:`.bezier` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``bezier.make_path_regular`` is deprecated. Use ``Path.cleaned()`` (or +``Path.cleaned(curves=True)``, etc.) instead (but note that these methods add a +``STOP`` code at the end of the path). + +``bezier.concatenate_paths`` is deprecated. Use ``Path.make_compound_path()`` +instead. diff --git a/lib/matplotlib/bezier.py b/lib/matplotlib/bezier.py index 8cec64f1582f..f5dbb59ba0f5 100644 --- a/lib/matplotlib/bezier.py +++ b/lib/matplotlib/bezier.py @@ -480,6 +480,8 @@ def make_wedged_bezier2(bezier2, width, w1=1., wm=0.5, w2=0.): return path_left, path_right +@cbook.deprecated( + "3.2", alternative="Path.cleaned() and remove the final STOP if needed") def make_path_regular(p): """ If the ``codes`` attribute of `.Path` *p* is None, return a copy of *p* @@ -495,6 +497,7 @@ def make_path_regular(p): return p +@cbook.deprecated("3.2", alternative="Path.make_compound_path()") def concatenate_paths(paths): """Concatenate a list of paths into a single path.""" vertices = np.concatenate([p.vertices for p in paths]) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index bc27ddbabaf4..f504a9a4c64b 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -10,10 +10,9 @@ import matplotlib as mpl from . import artist, cbook, colors, docstring, lines as mlines, transforms from .bezier import ( - NonIntersectingPathException, concatenate_paths, get_cos_sin, - get_intersection, get_parallels, inside_circle, make_path_regular, - make_wedged_bezier2, split_bezier_intersecting_with_closedpath, - split_path_inout) + NonIntersectingPathException, get_cos_sin, get_intersection, + get_parallels, inside_circle, make_wedged_bezier2, + split_bezier_intersecting_with_closedpath, split_path_inout) from .path import Path @@ -2873,8 +2872,6 @@ def __call__(self, path, mutation_size, linewidth, and takes care of the aspect ratio. """ - path = make_path_regular(path) - if aspect_ratio is not None: # Squeeze the given height by the aspect_ratio vertices = path.vertices / [1, aspect_ratio] @@ -2886,10 +2883,9 @@ def __call__(self, path, mutation_size, linewidth, if np.iterable(fillable): path_list = [] for p in zip(path_mutated): - v, c = p.vertices, p.codes # Restore the height - v[:, 1] = v[:, 1] * aspect_ratio - path_list.append(Path(v, c)) + path_list.append( + Path(p.vertices * [1, aspect_ratio], p.codes)) return path_list, fillable else: return path_mutated, fillable @@ -4125,7 +4121,7 @@ def get_path(self): """ _path, fillable = self.get_path_in_displaycoord() if np.iterable(fillable): - _path = concatenate_paths(_path) + _path = Path.make_compound_path(*_path) return self.get_transform().inverted().transform_path(_path) def get_path_in_displaycoord(self): diff --git a/lib/matplotlib/tests/test_artist.py b/lib/matplotlib/tests/test_artist.py index 1a5d4dc00a09..92ac982b5969 100644 --- a/lib/matplotlib/tests/test_artist.py +++ b/lib/matplotlib/tests/test_artist.py @@ -100,10 +100,7 @@ def test_clipping(): exterior.vertices -= 2 interior = mpath.Path.unit_circle().deepcopy() interior.vertices = interior.vertices[::-1] - clip_path = mpath.Path(vertices=np.concatenate([exterior.vertices, - interior.vertices]), - codes=np.concatenate([exterior.codes, - interior.codes])) + clip_path = mpath.Path.make_compound_path(exterior, interior) star = mpath.Path.unit_regular_star(6).deepcopy() star.vertices *= 2.6