From 5a872b057c7f0330bf603257e61e6ad7d3281165 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Sat, 2 Jun 2018 11:33:57 +0200 Subject: [PATCH] Raise TypeError on unsupported kwargs of spy() --- doc/api/next_api_changes/2018-06-02-TH.rst | 13 +++++++++++++ lib/matplotlib/axes/_axes.py | 10 +++++++--- lib/matplotlib/tests/test_axes.py | 8 ++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 doc/api/next_api_changes/2018-06-02-TH.rst diff --git a/doc/api/next_api_changes/2018-06-02-TH.rst b/doc/api/next_api_changes/2018-06-02-TH.rst new file mode 100644 index 000000000000..578a95c2ac1e --- /dev/null +++ b/doc/api/next_api_changes/2018-06-02-TH.rst @@ -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. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 3e3e92db43bd..a264fe7f2055 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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() @@ -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) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 6c1f7a2c4019..b73583eb51cc 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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():
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: