Skip to content

Raise TypeError on unsupported kwargs of spy() #11367

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
Sep 17, 2018
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
13 changes: 13 additions & 0 deletions doc/api/next_api_changes/2018-06-02-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Changes to `matplotlib.axes.Axes.spy`
-------------------------------------

The method `matplotlib.axes.Axes.spy` now raises a TypeError for the keyword
arguments 'interpolation' and 'linestyle' instead of silently ignoring them.

Furthermore, `matplotlib.axes.Axes.spy` spy does now allow for an 'extent'
argument (was silently ignored so far).

A bug with `spy(..., origin='lower') is fixed: So far this flipped the
data but not the y-axis resulting in a mismatch between axes labels and
actual data indices. Now, `origin='lower'` flips both the data and the y-axis
labels.
10 changes: 7 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7692,10 +7692,11 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
if 'cmap' not in kwargs:
kwargs['cmap'] = mcolors.ListedColormap(['w', 'k'],
name='binary')
nr, nc = Z.shape
extent = [-0.5, nc - 0.5, nr - 0.5, -0.5]
if 'interpolation' in kwargs:
raise TypeError(
"spy() got an unexpected keyword argument 'interpolation'")
ret = self.imshow(mask, interpolation='nearest', aspect=aspect,
extent=extent, origin=origin, **kwargs)
origin=origin, **kwargs)
else:
if hasattr(Z, 'tocoo'):
c = Z.tocoo()
Expand All @@ -7714,6 +7715,9 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
marker = 's'
if markersize is None:
markersize = 10
if 'linestyle' in kwargs:
raise TypeError(
"spy() got an unexpected keyword argument 'linestyle'")
marks = mlines.Line2D(x, y, linestyle='None',
marker=marker, markersize=markersize, **kwargs)
self.add_line(marks)
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def test_spy():
ax.spy(a)


def test_spy_invalid_kwargs():
fig, ax = plt.subplots()
for unsupported_kw in [{'interpolation': 'nearest'},
{'marker': 'o', 'linestyle': 'solid'}]:
with pytest.raises(TypeError):
ax.spy(np.eye(3, 3), **unsupported_kw)


@image_comparison(baseline_images=['matshow'],
extensions=['png'], style='mpl20')
def test_matshow():
Expand Down