diff --git a/lib/matplotlib/tests/test_triangulation.py b/lib/matplotlib/tests/test_triangulation.py index 6a281d60fe00..5559718935ae 100644 --- a/lib/matplotlib/tests/test_triangulation.py +++ b/lib/matplotlib/tests/test_triangulation.py @@ -1008,6 +1008,19 @@ def test_qhull_triangle_orientation(): assert_array_equal(qhull_neighbors, own_neighbors) +def test_trianalyzer_mismatched_indices(): + # github issue 4999. + x = np.array([0., 1., 0.5, 0., 2.]) + y = np.array([0., 0., 0.5*np.sqrt(3.), -1., 1.]) + triangles = np.array([[0, 1, 2], [0, 1, 3], [1, 2, 4]], dtype=np.int32) + mask = np.array([False, False, True], dtype=np.bool) + triang = mtri.Triangulation(x, y, triangles, mask=mask) + analyser = mtri.TriAnalyzer(triang) + # numpy >= 1.10 raises a VisibleDeprecationWarning in the following line + # prior to the fix. + triang2 = analyser._get_compressed_triangulation() + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tri/tritools.py b/lib/matplotlib/tri/tritools.py index 35e382c98a75..bd876c8cbe95 100644 --- a/lib/matplotlib/tri/tritools.py +++ b/lib/matplotlib/tri/tritools.py @@ -257,7 +257,8 @@ def _get_compressed_triangulation(self, return_tri_renum=False, tri_renum = self._total_to_compress_renum(tri_mask, ntri) # Valid nodes and renumbering - node_mask = (np.bincount(np.ravel(compressed_triangles)) == 0) + node_mask = (np.bincount(np.ravel(compressed_triangles), + minlength=self._triangulation.x.size) == 0) compressed_x = self._triangulation.x[~node_mask] compressed_y = self._triangulation.y[~node_mask] node_renum = self._total_to_compress_renum(node_mask)