8000 FIX: bbox_inches='tight' with only non-finite bounding boxes by tacaswell · Pull Request #13426 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: bbox_inches='tight' with only non-finite bounding boxes #13426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2366,11 +2366,14 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
except TypeError:
bbox = ax.get_tightbbox(renderer)
bb.append(bbox)
bb = [b for b in bb
if (np.isfinite(b.width) and np.isfinite(b.height)
and (b.width != 0 or b.height != 0))]

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

_bbox = Bbox.union([b for b in bb if b.width != 0 or b.height != 0])
_bbox = Bbox.union(bb)

bbox_inches = TransformedBbox(_bbox,
Affine2D().scale(1. / self.dpi))
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_bbox_tight.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from io import BytesIO

from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -86,3 +87,12 @@ def test_bbox_inches_tight_raster():
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1.0, 2.0], rasterized=True)


def test_only_on_non_finite_bbox():

fig, ax = plt.subplots()
ax.annotate("", xy=(0, float('nan')))
ax.set_axis_off()
# we only need to test that it does not error out on save
fig.savefig(BytesIO(), bbox_inches='tight', format='png')
0