Skip to content

Commit

Permalink
Merge pull request #27661 from dstansby/auto-backport-of-pr-27647-on-…
Browse files Browse the repository at this point in the history
…v3.8.x

Backport of pr 27647 on v3.8.x
  • Loading branch information
tacaswell committed Jan 17, 2024
2 parents 66642ff + 697c7cb commit e082a29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e082a29

Please sign in to comment.