Skip to content

Commit da5815d

Browse files
committed
fix minorticks_on
1 parent b20b1d8 commit da5815d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import matplotlib.pyplot as plt
1313
import matplotlib.ticker as mticker
1414

15+
import random
16+
1517

1618
class TestMaxNLocator:
1719
basic_data = [
@@ -1789,3 +1791,31 @@ def test_set_offset_string(formatter):
17891791
assert formatter.get_offset() == ''
17901792
formatter.set_offset_string('mpl')
17911793
assert formatter.get_offset() == 'mpl'
1794+
1795+
1796+
def test_minorticks_on_multi_fig():
1797+
"""
1798+
Turning on minor gridlines in a multi-Axes Figure
1799+
that contains more than one boxplot and shares the x-axis
1800+
should not raise an exception.
1801+
"""
1802+
fig, ax = plt.subplots(sharex=True, ncols=2, nrows=2)
1803+
1804+
def values():
1805+
return [random.random() for _ in range(9)]
1806+
1807+
for x in range(3):
1808+
ax[0, 0].boxplot(values(), positions=[x])
1809+
ax[0, 1].boxplot(values(), positions=[x])
1810+
ax[1, 0].boxplot(values(), positions=[x])
1811+
ax[1, 1].boxplot(values(), positions=[x])
1812+
1813+
for a in ax.flatten():
1814+
a.grid(which="major")
1815+
a.grid(which="minor", linestyle="--")
1816+
a.minorticks_on()
1817+
fig.canvas.draw()
1818+
1819+
assert all(a.get_xgridlines() for a in ax.flatten())
1820+
assert all((isinstance(a.xaxis.get_minor_locator(), mpl.ticker.AutoMinorLocator)
1821+
for a in ax.flatten()))

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ def __call__(self):
28812881
_api.warn_external('AutoMinorLocator does not work on logarithmic scales')
28822882
return []
28832883

2884-
majorlocs = self.axis.get_majorticklocs()
2884+
majorlocs = np.unique(self.axis.get_majorticklocs())
28852885
if len(majorlocs) < 2:
28862886
# Need at least two major ticks to find minor tick locations.
28872887
# TODO: Figure out a way to still be able to display minor ticks with less

0 commit comments

Comments
 (0)