Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0302451

Browse filesBrowse files
committed
FIX: bbox_inches='tight' with only non-finite bounding boxes
closes #13276
1 parent 665cf51 commit 0302451
Copy full SHA for 0302451

File tree

Expand file treeCollapse file tree

2 files changed

+14
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-1
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+4-1Lines 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.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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_bbox_tight.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
from io import BytesIO
23

34
from matplotlib.testing.decorators import image_comparison
45
import matplotlib.pyplot as plt
@@ -86,3 +87,12 @@ def test_bbox_inches_tight_raster():
8687
fig = plt.figure()
8788
ax = fig.add_subplot(111)
8889
ax.plot([1.0, 2.0], rasterized=True)
90+
91+
92+
def test_only_on_non_finite_bbox():
93+
94+
fig, ax = plt.subplots()
95+
ax.annotate("", xy=(0, float('nan')))
96+
ax.set_axis_off()
97+
# we only need to test that it does not error out on save
98+
fig.savefig(BytesIO(), bbox_inches='tight', format='png')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.