Skip to content

Commit b03407b

Browse files
authored
Merge pull request #27647 from saranti/minorticks
Fix error that occurs when minorticks are on multi-Axes Figure with more than one boxplot
2 parents 690aaf3 + 4a3df94 commit b03407b

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
@@ -1804,3 +1804,24 @@ def test_set_offset_string(formatter):
18041804
assert formatter.get_offset() == ''
18051805
formatter.set_offset_string('mpl')
18061806
assert formatter.get_offset() == 'mpl'
1807+
1808+
1809+
def test_minorticks_on_multi_fig():
1810+
"""
1811+
Turning on minor gridlines in a multi-Axes Figure
1812+
that contains more than one boxplot and shares the x-axis
1813+
should not raise an exception.
1814+
"""
1815+
fig, ax = plt.subplots()
1816+
1817+
ax.boxplot(np.arange(10), positions=[0])
1818+
ax.boxplot(np.arange(10), positions=[0])
1819+
ax.boxplot(np.arange(10), positions=[1])
1820+
1821+
ax.grid(which="major")
1822+
ax.grid(which="minor")
1823+
ax.minorticks_on()
1824+
fig.draw_without_rendering()
1825+
1826+
assert ax.get_xgridlines()
1827+
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
@@ -2903,7 +2903,7 @@ def __call__(self):
29032903
_api.warn_external('AutoMinorLocator does not work on logarithmic scales')
29042904
return []
29052905

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

0 commit comments

Comments
 (0)