Skip to content

Fix error that occurs when minorticks are on multi-Axes Figure with more than one boxplot #27647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down