8000 FIX: bbox_inches='tight' with only non-finite bounding boxes · matplotlib/matplotlib@1a4b6ee · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a4b6ee

Browse files
committed
FIX: bbox_inches='tight' with only non-finite bounding boxes
closes #13276
1 parent 665cf51 commit 1a4b6ee

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2366,11 +2366,14 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
23662366
except TypeError:
23672367
bbox = ax.get_tightbbox(renderer)
23682368
bb.append(bbox)
2369+
bb = [b for b in bb
2370+
if (np.isfinite(b.width) and np.isfinite(b.height)
2371+
and (b.width != 0 or b.height != 0))]
23692372

23702373
if len(bb) == 0:
23712374
return self.bbox_inches
23722375

2373-
_bbox = Bbox.union([b for b in bb if b.width != 0 or b.< 8000 /span>height != 0])
2376+
_bbox = Bbox.union(bb)
23742377

23752378
bbox_inches = TransformedBbox(_bbox,
23762379
Affine2D().scale(1. / self.dpi))

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,11 @@ def test_bbox_inches_tight_raster():
8686
fig = plt.figure()
8787
ax = fig.add_subplot(111)
8888
ax.plot([1.0, 2.0], rasterized=True)
89+
90+
91+
def test_only_on_non_finite_bbox():
92+
93+
fig, ax = plt.subplots()
94+
ax.annotate("", xy=(0, float('nan')))
95+
ax.set_axis_off()
96+
fig.savefig("bar.png", bbox_inches='tight')

0 commit comments

Comments
 (0)
0