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

Skip to content

Commit f56505c

Browse files
authored
Merge pull request #18983 from bakesbasha/spy_fix
Pass norm argument to spy
2 parents 4d3b10e + e703cae commit f56505c

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7659,8 +7659,11 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
76597659
if 'interpolation' in kwargs:
76607660
raise TypeError(
76617661
"spy() got an unexpected keyword argument 'interpolation'")
7662-
ret = self.imshow(mask, interpolation='nearest', aspect=aspect,
7663-
origin=origin, **kwargs)
7662+
if 'norm' not in kwargs:
7663+
kwargs['norm'] = mcolors.NoNorm()
7664+
ret = self.imshow(mask, interpolation='nearest',
7665+
aspect=aspect, origin=origin,
7666+
**kwargs)
76647667
else:
76657668
if hasattr(Z, 'tocoo'):
76667669
c = Z.tocoo()

lib/matplotlib/tests/test_image.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
NonUniformImage, PcolorImage)
1818
from matplotlib.testing.decorators import check_figures_equal, image_comparison
1919
from matplotlib.transforms import Bbox, Affine2D, TransformedBbox
20+
import matplotlib.ticker as mticker
2021

2122
import pytest
2223

@@ -1218,3 +1219,36 @@ def test_huge_range_log(fig_test, fig_ref):
12181219
ax = fig_ref.subplots()
12191220
im = ax.imshow(data, norm=colors.Normalize(vmin=100, vmax=data.max()),
12201221
interpolation='nearest', cmap=cmap)
1222+
1223+
1224+
@check_figures_equal()
1225+
def test_spy_box(fig_test, fig_ref):
1226+
# setting up reference and test
1227+
ax_test = fig_test.subplots(1, 3)
1228+
ax_ref = fig_ref.subplots(1, 3)
1229+
1230+
plot_data = (
1231+
[[1, 1], [1, 1]],
1232+
[[0, 0], [0, 0]],
1233+
[[0, 1], [1, 0]],
1234+
)
1235+
plot_titles = ["ones", "zeros", "mixed"]
1236+
1237+
for i, (z, title) in enumerate(zip(plot_data, plot_titles)):
1238+
ax_test[i].set_title(title)
1239+
ax_test[i].spy(z)
1240+
ax_ref[i].set_title(title)
1241+
ax_ref[i].imshow(z, interpolation='nearest',
1242+
aspect='equal', origin='upper', cmap='Greys',
1243+
vmin=0, vmax=1)
1244+
ax_ref[i].set_xlim(-0.5, 1.5)
1245+
ax_ref[i].set_ylim(1.5, -0.5)
1246+
ax_ref[i].xaxis.tick_top()
1247+
ax_ref[i].title.set_y(1.05)
1248+
ax_ref[i].xaxis.set_ticks_position('both')
1249+
ax_ref[i].xaxis.set_major_locator(
1250+
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)
1251+
)
1252+
ax_ref[i].yaxis.set_major_locator(
1253+
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)
1254+
)

0 commit comments

Comments
 (0)