diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index ff9a519ee185..202465847b5b 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -1797,3 +1797,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 5b1b7e11408c..47a06f3eec3a 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2895,7 +2895,7 @@ def __call__(self): 'logarithmic scale') return [] - majorlocs = self.axis.get_majorticklocs() + majorlocs = np.unique(self.axis.get_majorticklocs()) try: majorstep = majorlocs[1] - majorlocs[0] except IndexError: