Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6640e60

Browse files
committed
fix minorticks_on
1 parent cd8281b commit 6640e60

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import matplotlib.pyplot as plt
1313
import matplotlib.ticker as mticker
1414

15+
import random
16+
1517

1618
class TestMaxNLocator:
1719
basic_data = [
@@ -1796,3 +1798,31 @@ def test_set_offset_string(formatter):
17961798
assert formatter.get_offset() == ''
17971799
formatter.set_offset_string('mpl')
17981800
assert formatter.get_offset() == 'mpl'
1801+
1802+
1803+
def test_minorticks_on_multi_fig():
1804+
"""
1805+
Turning on minor gridlines in a multi-Axes Figure
1806+
that contains more than one boxplot and shares the x-axis
1807+
should not raise an exception.
1808+
"""
1809+
fig, ax = plt.subplots(sharex=True, ncols=2, nrows=2)
1810+
1811+
def values():
1812+
return [random.random() for _ in range(9)]
1813+
1814+
for x in range(3):
1815+
ax[0, 0].boxplot(values(), positions=[x])
1816+
ax[0, 1].boxplot(values(), positions=[x])
1817+
ax[1, 0].boxplot(values(), positions=[x])
1818+
ax[1, 1].boxplot(values(), positions=[x])
1819+
1820+
for a in ax.flatten():
1821+
a.grid(which="major")
1822+
a.grid(which="minor", linestyle="--")
1823+
a.minorticks_on()
1824+
fig.canvas.draw()
1825+
1826+
assert all(a.get_xgridlines() for a in ax.flatten())
1827+
assert all((isinstance(a.xaxis.get_minor_locator(), mpl.ticker.AutoMinorLocator)
1828+
for a in ax.flatten()))

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)