Skip to content

Commit 41f72fb

Browse files
authored
Merge pull request #12651 from jklymak/fix-ignore-non-finite-bbox
FIX: ignore non-finite bbox
2 parents 5eaa14c + 49570b4 commit 41f72fb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/matplotlib/axes/_base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4207,7 +4207,9 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
42074207

42084208
for a in bbox_artists:
42094209
bbox = a.get_tightbbox(renderer)
4210-
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
4210+
if (bbox is not None and
4211+
(bbox.width != 0 or bbox.height != 0) and
4212+
np.isfinite(bbox.width) and np.isfinite(bbox.height)):
42114213
bb.append(bbox)
42124214

42134215
_bbox = mtransforms.Bbox.union(

lib/matplotlib/tests/test_axes.py

+7
Original file line numberDiff line numberDiff line change
@@ -5849,3 +5849,10 @@ class DummySubplot(matplotlib.axes.SubplotBase, Dummy):
58495849
FactoryDummySubplot = matplotlib.axes.subplot_class_factory(Dummy)
58505850

58515851
assert DummySubplot is FactoryDummySubplot
5852+
5853+
5854+
def test_gettightbbox_ignoreNaN():
5855+
fig, ax = plt.subplots()
5856+
t = ax.text(np.NaN, 1, 'Boo')
5857+
renderer = fig.canvas.get_renderer()
5858+
np.testing.assert_allclose(ax.get_tightbbox(renderer).width, 532.444444)

0 commit comments

Comments
 (0)