diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 12eafba9ea2b..fcfdf8ee92f5 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -1796,3 +1796,24 @@ def test_set_offset_string(formatter): assert formatter.get_offset() == '' formatter.set_offset_string('mpl') assert formatter.get_offset() == 'mpl' + + +def test_minorticks_on_multi_fig(): + """ + Turning on minor gridlines in a multi-Axes Figure + that contains more than one boxplot and shares the x-axis + should not raise an exception. + """ + fig, ax = plt.subplots() + + ax.boxplot(np.arange(10), positions=[0]) + ax.boxplot(np.arange(10), positions=[0]) + ax.boxplot(np.arange(10), positions=[1]) + + ax.grid(which="major") + ax.grid(which="minor") + ax.minorticks_on() + fig.draw_without_rendering() + + assert ax.get_xgridlines() + assert isinstance(ax.xaxis.get_minor_locator(), mpl.ticker.AutoMinorLocator) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 10ac8cad6ebc..1e9f0892c322 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2903,7 +2903,7 @@ def __call__(self): _api.warn_external('AutoMinorLocator does not work on logarithmic scales') return [] - majorlocs = self.axis.get_majorticklocs() + majorlocs = np.unique(self.axis.get_majorticklocs()) if len(majorlocs) < 2: # Need at least two major ticks to find minor tick locations. # TODO: Figure out a way to still be able to display minor ticks with less