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

Skip to content

Commit ab4224a

Browse files
author
bakes
committed
Styling fixes to _axes.py, added test_spy.py for this change
1 parent a6be274 commit ab4224a

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7662,8 +7662,9 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
76627662
if 'interpolation' in kwargs:
76637663
raise TypeError(
76647664
"spy() got an unexpected keyword argument 'interpolation'")
7665-
ret = self.imshow(mask, norm=mcolors.NoNorm(), interpolation='nearest', aspect=aspect,
7666-
origin=origin, **kwargs)
7665+
ret = self.imshow(mask, norm=mcolors.NoNorm(),
7666+
interpolation='nearest', aspect=aspect,
7667+
origin=origin, **kwargs)
76677668
else:
76687669
if hasattr(Z, 'tocoo'):
76697670
c = Z.tocoo()

lib/matplotlib/tests/test_spy.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import matplotlib.ticker as mticker
2+
from matplotlib import pyplot as plt
3+
from matplotlib.testing.decorators import check_figures_equal
4+
5+
6+
@check_figures_equal()
7+
def test_spy_box(fig_test, fig_ref):
8+
# setting up reference and test
9+
ax_test = fig_test.subplots(1, 3)
10+
ax_ref = fig_ref.subplots(1, 3)
11+
12+
# plotting with spy
13+
ax_test[0].set_title("ones")
14+
ax_test[0].spy([[1, 1], [1, 1], ])
15+
ax_test[1].set_title("zeros")
16+
ax_test[1].spy([[0, 0], [0, 0], ])
17+
ax_test[2].set_title("mixed")
18+
ax_test[2].spy([[0, 1], [1, 0], ])
19+
20+
# plotting with imshow
21+
ax_ref[0].set_title("ones")
22+
ax_ref[0].imshow([[1, 1], [1, 1], ], interpolation='nearest',
23+
aspect='equal', origin='upper', cmap='Greys',
24+
vmin=0, vmax=1)
25+
ax_ref[0].set_xlim(-0.5, 1.5)
26+
ax_ref[0].set_ylim(1.5, -0.5)
27+
ax_ref[0].xaxis.tick_top()
28+
ax_ref[0].title.set_y(1.05)
29+
ax_ref[0].xaxis.set_ticks_position('both')
30+
ax_ref[0].xaxis.set_major_locator(
31+
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)
32+
)
33+
ax_ref[0].yaxis.set_major_locator(
34+
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)
35+
)
36+
37+
ax_ref[1].set_title("zeros")
38+
ax_ref[1].imshow([[0, 0], [0, 0], ], interpolation='nearest',
39+
aspect='equal', origin='upper', cmap='Greys',
40+
vmin=0, vmax=1)
41+
ax_ref[1].set_xlim(-0.5, 1.5)
42+
ax_ref[1].set_ylim(1.5, -0.5)
43+
ax_ref[1].xaxis.tick_top()
44+
ax_ref[1].title.set_y(1.05)
45+
ax_ref[1].xaxis.set_ticks_position('both')
46+
ax_ref[1].xaxis.set_major_locator(
47+
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)
48+
)
49+
ax_ref[1].yaxis.set_major_locator(
50+
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)
51+
)
52+
53+
ax_ref[2].set_title("mixed")
54+
ax_ref[2].imshow([[0, 1], [1, 0], ], interpolation='nearest',
55+
aspect='equal', origin='upper', cmap='Greys',
56+
vmin=0, vmax=1)
57+
ax_ref[2].set_xlim(-0.5, 1.5)
58+
ax_ref[2].set_ylim(1.5, -0.5)
59+
ax_ref[2].xaxis.tick_top()
60+
ax_ref[2].title.set_y(1.05)
61+
ax_ref[2].xaxis.set_ticks_position('both')
62+
ax_ref[2].xaxis.set_major_locator(
63+
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)
64+
)
65+
ax_ref[2].yaxis.set_major_locator(
66+
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)
67+
)
68+
69+

0 commit comments

Comments
 (0)