Skip to content

Commit b47faf4

Browse files
authored
Merge pull request #12668 from meeseeksmachine/auto-backport-of-pr-12651-on-v3.0.x
Backport PR #12651 on branch v3.0.x (FIX: ignore non-finite bbox)
2 parents af9a17b + 2095a54 commit b47faf4

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
@@ -4238,7 +4238,9 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
42384238

42394239
for a in bbox_artists:
42404240
bbox = a.get_tightbbox(renderer)
4241-
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
4241+
if (bbox is not None and
4242+
(bbox.width != 0 or bbox.height != 0) and
4243+
np.isfinite(bbox.width) and np.isfinite(bbox.height)):
42424244
bb.append(bbox)
42434245

42444246
_bbox = mtransforms.Bbox.union(

lib/matplotlib/tests/test_axes.py

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

58435843
assert DummySubplot is FactoryDummySubplot
5844+
5845+
5846+
def test_gettightbbox_ignoreNaN():
5847+
fig, ax = plt.subplots()
5848+
t = ax.text(np.NaN, 1, 'Boo')
5849+
renderer = fig.canvas.get_renderer()
5850+
np.testing.assert_allclose(ax.get_tightbbox(renderer).width, 532.444444)

0 commit comments

Comments
 (0)