8000 Merge pull request #27647 from saranti/minorticks · matplotlib/matplotlib@697c7cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 697c7cb

Browse files
committed
Merge pull request #27647 from saranti/minorticks
Fix error that occurs when minorticks are on multi-Axes Figure with more than one boxplot (cherry picked from commit b03407b)
1 parent 1b8f49e commit 697c7cb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,3 +1797,24 @@ def test_set_offset_string(formatter):
17971797
assert formatter.get_offset() == ''
17981798
formatter.set_offset_string('mpl')
17991799
assert formatter.get_offset() == 'mpl'
1800+
1801+
1802+
def test_minorticks_on_multi_fig():
1803+
"""
1804+
Turning on minor gridlines in a multi-Axes Figure
1805+
that contains more than one boxplot and shares the x-axis
1806+
should not raise an exception.
1807+
"""
1808+
fig, ax = plt.subplots()
1809+
1810+
ax.boxplot(np.arange(10), positions=[0])
1811+
ax.boxplot(np.arange(10), positions=[0])
1812+
ax.boxplot(np.arange(10), positions=[1])
1813+
1814+
ax.grid(which="major")
1815+
ax.grid(which="minor")
1816+
ax.minorticks_on()
1817+
fig.draw_without_rendering()
1818+
1819+
assert ax.get_xgridlines()
1820+
assert isinstance(ax.xaxis.get_minor_locator(), mpl.ticker.AutoMinorLocator)

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ def __call__(self):
28952895
'logarithmic scale')
28962896
return []
28972897

2898-
majorlocs = self.axis.get_majorticklocs()
2898+
majorlocs = np.unique(self.axis.get_majorticklocs())
28992899
try:
29002900
majorstep = majorlocs[1] - majorlocs[0]
29012901
except IndexError:

0 commit comments

Comments
 (0)
0