Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,13 @@ def make_compound_path_from_polys(cls, XY):

@classmethod
def make_compound_path(cls, *args):
"""Make a compound path from a list of Path objects."""
"""
Make a compound path from a list of Path objects. Blindly removes all
Path.STOP control points.
"""
# Handle an empty list in args (i.e. no args).
if not args:
return Path(np.empty([0, 2], dtype=np.float32))

vertices = np.concatenate([x.vertices for x in args])
codes = np.empty(len(vertices), dtype=cls.code_type)
i = 0
Expand All @@ -340,6 +342,10 @@ def make_compound_path(cls, *args):
else:
codes[i:i + len(path.codes)] = path.codes
i += len(path.vertices)
# remove STOP's, since internal STOPs are a bug
not_stop_mask = codes != cls.STOP
vertices = vertices[not_stop_mask, :]
codes = codes[not_stop_mask]

return cls(vertices, codes)

Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ def test_make_compound_path_empty():
assert r.vertices.shape == (0, 2)


def test_make_compound_path_stops():
zero = [0, 0]
paths = 3*[Path([zero, zero], [Path.MOVETO, Path.STOP])]
compound_path = Path.make_compound_path(*paths)
# the choice to not preserve the terminal STOP is arbitrary, but
# documented, so we test that it is in fact respected here
assert np.sum(compound_path.codes == Path.STOP) == 0


@image_comparison(['xkcd.png'], remove_text=True)
def test_xkcd():
np.random.seed(0)
Expand Down