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

Skip to content

Commit 3abe033

Browse files
committed
Raise IgnoredKeywordWarning on unsupported kwargs of spy()
1 parent e5d5d40 commit 3abe033

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
MatplotlibDeprecationWarning, 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

@@ -7695,10 +7695,13 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
76957695
if 'cmap' not in kwargs:
76967696
kwargs['cmap'] = mcolors.ListedColormap(['w', 'k'],
76977697
name='binary')
7698-
nr, nc = Z.shape
7699-
extent = [-0.5, nc - 0.5, nr - 0.5, -0.5]
7698+
if 'interpolation' in kwargs:
7699+
kwargs.pop('interpolation')
7700+
warnings.warn(
7701+
'"interpolation" keyword argument will be ignored',
7702+
IgnoredKeywordWarning)
77007703
ret = self.imshow(mask, interpolation='nearest', aspect=aspect,
7701-
extent=extent, origin=origin, **kwargs)
7704+
origin=origin, **kwargs)
77027705
else:
77037706
if hasattr(Z, 'tocoo'):
77047707
c = Z.tocoo()
@@ -7717,6 +7720,11 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
77177720
marker = 's'
77187721
if markersize is None:
77197722
markersize = 10
7723+
if 'linestyle' in kwargs:
7724+
kwargs.pop('linestyle')
7725+
warnings.warn(
7726+
'"linestyle" keyword argument will be ignored',
7727+
IgnoredKeywordWarning)
77207728
marks = mlines.Line2D(x, y, linestyle='None',
77217729
marker=marker, markersize=markersize, **kwargs)
77227730
self.add_line(marks)

lib/matplotlib/tests/test_axes.py

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

6464

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

0 commit comments

Comments
 (0)