Skip to content
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
4 changes: 2 additions & 2 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def __setitem__(self, key, value):
super(_ColorMapping, self).__setitem__(key, value)
self.cache.clear()

def __delitem__(self, key, value):
super(_ColorMapping, self).__delitem__(key, value)
def __delitem__(self, key):
super(_ColorMapping, self).__delitem__(key)
self.cache.clear()


Expand Down
11 changes: 10 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ def __init__(self,
if frameon is None:
frameon = rcParams['figure.frameon']

if not np.isfinite(figsize).all():
raise ValueError('figure size must be finite not '
'{}'.format(figsize))
self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)

self.dpi_scale_trans = Affine2D().scale(dpi, dpi)
# do not use property as it will trigger
self._dpi = dpi
Expand Down Expand Up @@ -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)):

Copy link
Copy Markdown
Contributor

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()

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds fair

raise ValueError('figure size must be finite not '
'({}, {})'.format(w, h))
dpival = self.dpi
self.bbox_inches.p1 = w, h

Expand Down Expand Up @@ -920,6 +926,9 @@ def add_axes(self, *args, **kwargs):
raise ValueError(msg)
else:
rect = args[0]
if not np.isfinite(rect).all():
raise ValueError('all entries in rect must be finite '
'not {}'.format(rect))
projection_class, kwargs, key = process_projection_requirements(
self, *args, **kwargs)

Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,15 @@ def test_change_dpi():
fig.canvas.draw()
assert fig.canvas.renderer.height == 200
assert fig.canvas.renderer.width == 200


def test_invalid_figure_size():
with pytest.raises(ValueError):
plt.figure(figsize=(1, np.nan))

fig = plt.figure()
with pytest.raises(ValueError):
fig.set_size_inches(1, np.nan)

with pytest.raises(ValueError):
fig.add_axes((.1, .1, .5, np.nan))