diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 000bb38befd1..936455acd6c5 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -645,14 +645,16 @@ def splity(self, *args): def count_contains(self, vertices): """ Count the number of vertices contained in the :class:`Bbox`. + Any vertices with a non-finite x or y value are ignored. *vertices* is a Nx2 Numpy array. """ if len(vertices) == 0: return 0 vertices = np.asarray(vertices) - return ( - ((self.min < vertices) & (vertices < self.max)).all(axis=1).sum()) + with np.errstate(invalid='ignore'): + return (((self.min < vertices) & + (vertices < self.max)).all(axis=1).sum()) def count_overlaps(self, bboxes): """