diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py index 3b4e6e849cd7..e244dfa20040 100644 --- a/lib/matplotlib/path.py +++ b/lib/matplotlib/path.py @@ -326,6 +326,10 @@ 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.""" + # Handle an empty list in args (i.e. no args). + if not args: + return Path(np.empty([0, 2], dtype=np.float32)) + lengths = [len(x) for x in args] total_length = sum(lengths) diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index 090409a608da..124620dcfa50 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -7,7 +7,7 @@ from matplotlib.path import Path from matplotlib.patches import Polygon -from nose.tools import assert_raises +from nose.tools import assert_raises, assert_equal from matplotlib.testing.decorators import image_comparison import matplotlib.pyplot as plt @@ -70,6 +70,13 @@ def test_point_in_path_nan(): assert not contains[0] +def test_make_compound_path_empty(): + # We should be able to make a compound path with no arguments. + # This makes it easier to write generic path based code. + r = Path.make_compound_path() + assert_equal(r.vertices.shape, (0, 2)) + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)