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

Skip to content

Commit d01b3d1

Browse files
authored
Merge pull request #13069 from hershen/five_minor_ticks_2.5_major_ticks
5 minor divisions when major ticks are 2.5 units apart
2 parents 56755e4 + 4e227bd commit d01b3d1

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Adjust default minor tick spacing
2+
`````````````````````````````````
3+
4+
Default minor tick spacing was changed from 0.625 to 0.5 for major ticks spaced
5+
2.5 units apart.

lib/matplotlib/tests/test_ticker.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def test_basic(self):
9999
# NB: the following values are assuming that *xlim* is [0, 5]
100100
params = [
101101
(0, 0), # no major tick => no minor tick either
102-
(1, 0), # a single major tick => no minor tick
103-
(2, 4), # 1 "nice" major step => 1*5 minor **divisions**
104-
(3, 6) # 2 "not nice" major steps => 2*4 minor **divisions**
102+
(1, 0) # a single major tick => no minor tick
105103
]
106104

107105
@pytest.mark.parametrize('nb_majorticks, expected_nb_minorticks', params)
@@ -116,6 +114,32 @@ def test_low_number_of_majorticks(
116114
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
117115
assert len(ax.xaxis.get_minorticklocs()) == expected_nb_minorticks
118116

117+
majorstep_minordivisions = [(1, 5),
118+
(2, 4),
119+
(2.5, 5),
120+
(5, 5),
121+
(10, 5)]
122+
123+
# This test is meant to verify the parameterization for
124+
# test_number_of_minor_ticks
125+
def test_using_all_default_major_steps(self):
126+
with matplotlib.rc_context({'_internal.classic_mode': False}):
127+
majorsteps = [x[0] for x in self.majorstep_minordivisions]
128+
assert np.allclose(majorsteps, mticker.AutoLocator()._steps)
129+
130+
@pytest.mark.parametrize('major_step, expected_nb_minordivisions',
131+
majorstep_minordivisions)
132+
def test_number_of_minor_ticks(
133+
self, major_step, expected_nb_minordivisions):
134+
fig, ax = plt.subplots()
135+
xlims = (0, major_step)
136+
ax.set_xlim(*xlims)
137+
ax.set_xticks(xlims)
138+
ax.minorticks_on()
139+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
140+
nb_minor_divisions = len(ax.xaxis.get_minorticklocs()) + 1
141+
assert nb_minor_divisions == expected_nb_minordivisions
142+
119143
limits = [(0, 1.39), (0, 0.139),
120144
(0, 0.11e-19), (0, 0.112e-12),
121145
(-2.0e-07, -3.3e-08), (1.20e-06, 1.42e-06),

lib/matplotlib/ticker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,8 +2620,10 @@ def __call__(self):
26202620
return []
26212621

26222622
if self.ndivs is None:
2623-
x = int(np.round(10 ** (np.log10(majorstep) % 1)))
2624-
if x in [1, 5, 10]:
2623+
2624+
majorstep_no_exponent = 10 ** (np.log10(majorstep) % 1)
2625+
2626+
if np.isclose(majorstep_no_exponent, [1.0, 2.5, 5.0, 10.0]).any():
26252627
ndivs = 5
26262628
else:
26272629
ndivs = 4

0 commit comments

Comments
 (0)