diff --git a/.travis.yml b/.travis.yml index 8a120b5103..99b7626fbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -116,6 +116,9 @@ jobs: - popd - mv doc/Tutorials/.coverage ./.coverage - coveralls + after_failure: + - popd + - sleep 10 - <<: *regression_test env: DESC="Python 2.7 regression tests" PYENV_VERSION=2.7 HV_REQUIREMENTS="nbtests" diff --git a/holoviews/plotting/mpl/util.py b/holoviews/plotting/mpl/util.py index 701744afa6..473993ae24 100644 --- a/holoviews/plotting/mpl/util.py +++ b/holoviews/plotting/mpl/util.py @@ -318,6 +318,7 @@ def ring_coding(array): n = len(array) codes = np.ones(n, dtype=Path.code_type) * Path.LINETO codes[0] = Path.MOVETO + codes[-1] = Path.CLOSEPOLY return codes @@ -338,7 +339,13 @@ def polygons_to_path_patches(element): for j, array in enumerate(arrays): if j != (len(arrays)-1): array = array[:-1] - interiors = holes[i][j] if has_holes else [] + if (array[0] != array[-1]).any(): + array = np.append(array, array[:1], axis=0) + interiors = [] + for interior in (holes[i][j] if has_holes else []): + if (interior[0] != interior[-1]).any(): + interior = np.append(interior, interior[:1], axis=0) + interiors.append(interior) vertices = np.concatenate([array]+interiors) codes = np.concatenate([ring_coding(array)]+ [ring_coding(h) for h in interiors]) diff --git a/holoviews/tests/plotting/matplotlib/testpathplot.py b/holoviews/tests/plotting/matplotlib/testpathplot.py index 71fb9703e4..700de7850b 100644 --- a/holoviews/tests/plotting/matplotlib/testpathplot.py +++ b/holoviews/tests/plotting/matplotlib/testpathplot.py @@ -78,10 +78,10 @@ def test_polygon_with_hole_plot(self): self.assertEqual(len(paths), 1) path = paths[0] self.assertEqual(path.vertices, np.array([ - (1, 2), (2, 0), (3, 7), (1.5, 2), (2, 3), (1.6, 1.6), - (2.1, 4.5), (2.5, 5), (2.3, 3.5)]) + (1, 2), (2, 0), (3, 7), (1, 2), (1.5, 2), (2, 3), (1.6, 1.6), + (1.5, 2), (2.1, 4.5), (2.5, 5), (2.3, 3.5), (2.1, 4.5)]) ) - self.assertEqual(path.codes, np.array([1, 2, 2, 1, 2, 2, 1, 2, 2])) + self.assertEqual(path.codes, np.array([1, 2, 2, 79, 1, 2, 2, 79, 1, 2, 2, 79])) def test_multi_polygon_hole_plot(self): xs = [1, 2, 3, np.nan, 6, 7, 3] @@ -98,13 +98,13 @@ def test_multi_polygon_hole_plot(self): self.assertEqual(len(paths), 2) path = paths[0] self.assertEqual(path.vertices, np.array([ - (1, 2), (2, 0), (3, 7), (1.5, 2), (2, 3), (1.6, 1.6), - (2.1, 4.5), (2.5, 5), (2.3, 3.5)]) + (1, 2), (2, 0), (3, 7), (1, 2), (1.5, 2), (2, 3), (1.6, 1.6), + (1.5, 2), (2.1, 4.5), (2.5, 5), (2.3, 3.5), (2.1, 4.5)]) ) - self.assertEqual(path.codes, np.array([1, 2, 2, 1, 2, 2, 1, 2, 2])) + self.assertEqual(path.codes, np.array([1, 2, 2, 79, 1, 2, 2, 79, 1, 2, 2, 79])) path2 = paths[1] - self.assertEqual(path2.vertices, np.array([(6, 7), (7, 5), (3, 2)])) - self.assertEqual(path2.codes, np.array([1, 2, 2])) + self.assertEqual(path2.vertices, np.array([(6, 7), (7, 5), (3, 2), (6, 7)])) + self.assertEqual(path2.codes, np.array([1, 2, 2, 79])) def test_polygons_color_op(self): polygons = Polygons([ diff --git a/holoviews/tests/plotting/matplotlib/testutils.py b/holoviews/tests/plotting/matplotlib/testutils.py new file mode 100644 index 0000000000..0b08334df5 --- /dev/null +++ b/holoviews/tests/plotting/matplotlib/testutils.py @@ -0,0 +1,36 @@ +from __future__ import absolute_import, unicode_literals + +import numpy as np + +from holoviews.element import Polygons +from holoviews.plotting.mpl.util import polygons_to_path_patches + +from .testplot import TestMPLPlot + + +class TestUtils(TestMPLPlot): + + def test_polygon_to_path_patches(self): + xs = [1, 2, 3, np.nan, 6, 7, 3, np.nan, 0, 0, 0] + ys = [2, 0, 7, np.nan, 7, 5, 2, np.nan, 0, 1, 0] + + holes = [ + [[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]], + [], + [] + ] + polys = Polygons([{'x': xs, 'y': ys, 'holes': holes}]) + paths = polygons_to_path_patches(polys) + + + self.assertEqual(len(paths), 1) + self.assertEqual(len(paths[0]), 3) + self.assertEqual(paths[0][0].get_path().vertices, np.array([ + (1, 2), (2, 0), (3, 7), (1, 2), + (1.5, 2), (2, 3), (1.6, 1.6), (1.5, 2), + (2.1, 4.5), (2.5, 5), (2.3, 3.5), (2.1, 4.5)])) + self.assertEqual(paths[0][0].get_path().codes, np.array([1, 2, 2, 79, 1, 2, 2, 79, 1, 2, 2, 79], dtype='uint8')) + self.assertEqual(paths[0][1].get_path().vertices, np.array([(6, 7), (7, 5), (3, 2), (6, 7)])) + self.assertEqual(paths[0][1].get_path().codes, np.array([1, 2, 2, 79], dtype='uint8')) + self.assertEqual(paths[0][2].get_path().vertices, np.array([(0, 0), (0, 1), (0, 0)])) + self.assertEqual(paths[0][1].get_path().codes, np.array([1, 2, 2, 79], dtype='uint8'))