-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: fail early for non-finite figure sizes #8647
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
Conversation
lib/matplotlib/figure.py
Outdated
@@ -325,6 +325,10 @@ def __init__(self, | |||
frameon = rcParams['figure.frameon'] | |||
|
|||
self.bbox_inches = Bbox.from_bounds(0, 0, *figsize) | |||
if not all(np.isfinite(_) for _ in figsize): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not check this before the expense of creating a Bbox
(not that I know if that's a very large expense or not)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just write np.isfinite(figsize).all()
(and similarly below): the ufunc will cast the input to an ndarray.
lib/matplotlib/figure.py
Outdated
@@ -710,7 +714,9 @@ def set_size_inches(self, w, h=None, forward=True): | |||
# argument, so unpack them | |||
if h is None: | |||
w, h = w | |||
|
|||
if not all(np.isfinite(_) for _ in (h, w)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really picky, but it's kind of weird to have it be h, w
when everything around it is w, h
.
bef16b4
to
a4999ac
Compare
@@ -710,7 +714,9 @@ def set_size_inches(self, w, h=None, forward=True): | |||
# argument, so unpack them | |||
if h is None: | |||
w, h = w | |||
|
|||
if not all(np.isfinite(_) for _ in (w, h)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.isfinite([w, h]).all()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not convinced going through numpy is better in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds fair
Closes #8640
PR Summary
If passed non-finite values to figure size or add_axes, raise immediately rather than at draw time.
PR Checklist