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 989d061

Browse filesBrowse files
authored
Merge pull request #11367 from timhoffm/axes-spy-ignored-kwags
Raise TypeError on unsupported kwargs of spy()
2 parents 82a4b24 + 5a872b0 commit 989d061
Copy full SHA for 989d061

File tree

Expand file treeCollapse file tree

3 files changed

+28
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+28
-3
lines changed
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Changes to `matplotlib.axes.Axes.spy`
2+
-------------------------------------
3+
4+
The method `matplotlib.axes.Axes.spy` now raises a TypeError for the keyword
5+
arguments 'interpolation' and 'linestyle' instead of silently ignoring them.
6+
7+
Furthermore, `matplotlib.axes.Axes.spy` spy does now allow for an 'extent'
8+
argument (was silently ignored so far).
9+
10+
A bug with `spy(..., origin='lower') is fixed: So far this flipped the
11+
data but not the y-axis resulting in a mismatch between axes labels and
12+
actual data indices. Now, `origin='lower'` flips both the data and the y-axis
13+
labels.

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7694,10 +7694,11 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
76947694
if 'cmap' not in kwargs:
76957695
kwargs['cmap'] = mcolors.ListedColormap(['w', 'k'],
76967696
name='binary')
7697-
nr, nc = Z.shape
7698-
extent = [-0.5, nc - 0.5, nr - 0.5, -0.5]
7697+
if 'interpolation' in kwargs:
7698+
raise TypeError(
7699+
"spy() got an unexpected keyword argument 'interpolation'")
76997700
ret = self.imshow(mask, interpolation='nearest', aspect=aspect,
7700-
extent=extent, origin=origin, **kwargs)
7701+
origin=origin, **kwargs)
77017702
else:
77027703
if hasattr(Z, 'tocoo'):
77037704
c = Z.tocoo()
@@ -7716,6 +7717,9 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
77167717
marker = 's'
77177718
if markersize is None:
77187719
markersize = 10
7720+
if 'linestyle' in kwargs:
7721+
raise TypeError(
7722+
"spy() got an unexpected keyword argument 'linestyle'")
77197723
marks = mlines.Line2D(x, y, linestyle='None',
77207724
marker=marker, markersize=markersize, **kwargs)
77217725
self.add_line(marks)

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ def test_spy():
6262
ax.spy(a)
6363

6464

65+
def test_spy_invalid_kwargs():
66+
fig, ax = plt.subplots()
67+
for unsupported_kw in [{'interpolation': 'nearest'},
68+
{'marker': 'o', 'linestyle': 'solid'}]:
69+
with pytest.raises(TypeError):
70+
ax.spy(np.eye(3, 3), **unsupported_kw)
71+
72+
6573
@image_comparison(baseline_images=['matshow'],
6674
extensions=['png'], style='mpl20')
6775
def test_matshow():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.