Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 393e6db

Browse files
committed
Raise TypeError on unsupported kwargs of spy()
1 parent 391c0cb commit 393e6db

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed
Lines 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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7358,10 +7358,11 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
73587358
if 'cmap' not in kwargs:
73597359
kwargs['cmap'] = mcolors.ListedColormap(['w', 'k'],
73607360
name='binary')
7361-
nr, nc = Z.shape
7362-
extent = [-0.5, nc - 0.5, nr - 0.5, -0.5]
7361+
if 'interpolation' in kwargs:
7362+
raise TypeError(
7363+
"spy() got an unexpected keyword argument 'interpolation'")
73637364
ret = self.imshow(mask, interpolation='nearest', aspect=aspect,
7364-
extent=extent, origin=origin, **kwargs)
7365+
origin=origin, **kwargs)
73657366
else:
73667367
if hasattr(Z, 'tocoo'):
73677368
c = Z.tocoo()
@@ -7380,6 +7381,9 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
73807381
marker = 's'
73817382
if markersize is None:
73827383
markersize = 10
7384+
if 'linestyle' in kwargs:
7385+
raise TypeError(
7386+
"spy() got an unexpected keyword argument 'linestyle'")
73837387
marks = mlines.Line2D(x, y, linestyle='None',
73847388
marker=marker, markersize=markersize, **kwargs)
73857389
self.add_line(marks)

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def test_spy():
6161
ax.spy(a)
6262

6363

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

0 commit comments

Comments
 (0)