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

Skip to content

Commit 736b1d2

Browse files
committed
Raise IgnoredKeywordWarning on unsupported kwargs of spy()
1 parent b078643 commit 736b1d2

File tree

3 files changed

+37
-4
lines changed

3 files changed

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

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import matplotlib.tri as mtri
3636
from matplotlib.cbook import (
3737
mplDeprecation, warn_deprecated, STEP_LOOKUP_MAP, iterable,
38-
safe_first_element)
38+
safe_first_element, IgnoredKeywordWarning)
3939
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
4040
from matplotlib.axes._base import _AxesBase, _process_plot_format
4141

@@ -7397,10 +7397,13 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
73977397
if 'cmap' not in kwargs:
73987398
kwargs['cmap'] = mcolors.ListedColormap(['w', 'k'],
73997399
name='binary')
7400-
nr, nc = Z.shape
7401-
extent = [-0.5, nc - 0.5, nr - 0.5, -0.5]
7400+
if 'interpolation' in kwargs:
7401+
kwargs.pop('interpolation')
7402+
warnings.warn(
7403+
'"interpolation" keyword argument will be ignored',
7404+
IgnoredKeywordWarning)
74027405
ret = self.imshow(mask, interpolation='nearest', aspect=aspect,
7403-
extent=extent, origin=origin, **kwargs)
7406+
origin=origin, **kwargs)
74047407
else:
74057408
if hasattr(Z, 'tocoo'):
74067409
c = Z.tocoo()
@@ -7419,6 +7422,11 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
74197422
marker = 's'
74207423
if markersize is None:
74217424
markersize = 10
7425+
if 'linestyle' in kwargs:
7426+
kwargs.pop('linestyle')
7427+
warnings.warn(
7428+
'"linestyle" keyword argument will be ignored',
7429+
IgnoredKeywordWarning)
74227430
marks = mlines.Line2D(x, y, linestyle='None',
74237431
marker=marker, markersize=markersize, **kwargs)
74247432
self.add_line(marks)

lib/matplotlib/tests/test_axes.py

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

6363

64+
def test_spy_warn_ignored_kwargs():
65+
fig, ax = plt.subplots()
66+
for unsupported_kw in [{'interpolation': 'nearest'},
67+
{'marker': 'o', 'linestyle': 'solid'}]:
68+
with warnings.catch_warnings(record=True) as w:
69+
warnings.simplefilter("always")
70+
ax.spy(np.eye(3, 3), **unsupported_kw)
71+
assert len(w) == 1
72+
assert issubclass(w[0].category, IgnoredKeywordWarning)
73+
74+
6475
@image_comparison(baseline_images=['matshow'],
6576
extensions=['png'], style='mpl20')
6677
def test_matshow():

0 commit comments

Comments
 (0)