Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ab6b24

Browse files
committed
BUG : bbox with any nan points can not overlap
Fixes #4309
1 parent 94e6944 commit 3ab6b24

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/matplotlib/tests/test_transforms.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from nose.tools import assert_equal, assert_raises
1010
import numpy.testing as np_test
1111
from numpy.testing import assert_almost_equal, assert_array_equal
12-
from matplotlib.transforms import Affine2D, BlendedGenericTransform
12+
from matplotlib.transforms import Affine2D, BlendedGenericTransform, Bbox
1313
from matplotlib.path import Path
1414
from matplotlib.scale import LogScale
1515
from matplotlib.testing.decorators import cleanup, image_comparison
@@ -501,6 +501,12 @@ def test_log_transform():
501501
ax.set_yscale('log')
502502
ax.transData.transform((1,1))
503503

504+
@cleanup
505+
def test_nan_overlap():
506+
a = Bbox([[0, 0], [1, 1]])
507+
b = Bbox([[0, 0], [1, np.nan]])
508+
assert not a.overlaps(b)
509+
504510

505511
if __name__=='__main__':
506512
import nose

lib/matplotlib/transforms.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ def overlaps(self, other):
447447
"""
448448
ax1, ay1, ax2, ay2 = self._get_extents()
449449
bx1, by1, bx2, by2 = other._get_extents()
450+
if any(np.isnan(v) for v in [ax1, ay1, ax2, ay2, bx1, by1, bx2, by2]):
451+
return False
450452

451453
if ax2 < ax1:
452454
ax2, ax1 = ax1, ax2

0 commit comments

Comments
 (0)