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 be8bdbc

Browse filesBrowse files
authored
Merge pull request matplotlib#13461 from meeseeksmachine/auto-backport-of-pr-13426-on-v3.0.x
Backport PR matplotlib#13426 on branch v3.0.x (FIX: bbox_inches='tight' with only non-finite bounding boxes)
2 parents 2ab4767 + cd81f49 commit be8bdbc
Copy full SHA for be8bdbc

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
@@ -2281,11 +2281,14 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
22812281
except TypeError:
22822282
bbox = ax.get_tightbbox(renderer)
22832283
bb.append(bbox)
2284+
bb = [b for b in bb
2285+
if (np.isfinite(b.width) and np.isfinite(b.height)
2286+
and (b.width != 0 or b.height != 0))]
22842287

22852288
if len(bb) == 0:
22862289
return self.bbox_inches
22872290

2288-
_bbox = Bbox.union([b for b in bb if b.width != 0 or b.height != 0])
2291+
_bbox = Bbox.union(bb)
22892292

22902293
bbox_inches = TransformedBbox(_bbox,
22912294
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.