From 1930b42e515e42b188a8cf8a6fc7f99da05d755d Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sat, 27 Oct 2018 10:10:43 -0700 Subject: [PATCH 1/2] FIX: ignore non-finite bbox --- lib/matplotlib/axes/_base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e6b368d0117a..6981cbef280c 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -4259,7 +4259,9 @@ def get_tightbbox(self, renderer, call_axes_locator=True, for a in bbox_artists: bbox = a.get_tightbbox(renderer) - if bbox is not None and (bbox.width != 0 or bbox.height != 0): + if (bbox is not None and + (bbox.width != 0 or bbox.height != 0) and + np.isfinite(bbox.width) and np.isfinite(bbox.height)): bb.append(bbox) _bbox = mtransforms.Bbox.union( From 49570b4ea5bef4b338fcfba2e19f95f75b1478ee Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sat, 27 Oct 2018 13:42:57 -0700 Subject: [PATCH 2/2] TST: add tightbbox test --- lib/matplotlib/tests/test_axes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b4879e3b208a..08bff9272930 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5849,3 +5849,10 @@ class DummySubplot(matplotlib.axes.SubplotBase, Dummy): FactoryDummySubplot = matplotlib.axes.subplot_class_factory(Dummy) assert DummySubplot is FactoryDummySubplot + + +def test_gettightbbox_ignoreNaN(): + fig, ax = plt.subplots() + t = ax.text(np.NaN, 1, 'Boo') + renderer = fig.canvas.get_renderer() + np.testing.assert_allclose(ax.get_tightbbox(renderer).width, 532.444444)