8000 5 minor divisions when major ticks are 2.5 units apart by hershen · Pull Request #13069 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
8000

5 minor divisions when major ticks are 2.5 units apart #13069

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 1 commit into from
Feb 11, 2019
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Adjust default minor tick spacing
`````````````````````````````````

Default minor tick spacing was changed from 0.625 to 0.5 for major ticks spaced
2.5 units apart.
30 changes: 27 additions & 3 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ def test_basic(self):
# NB: the following values are assuming that *xlim* is [0, 5]
params = [
(0, 0), # no major tick => no minor tick either
(1, 0), # a single major tick => no minor tick
(2, 4), # 1 "nice" major step => 1*5 minor **divisions**
(3, 6) # 2 "not nice" major steps => 2*4 minor **divisions**
(1, 0) # a single major tick => no minor tick
]

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

majorstep_minordivisions = [(1, 5),
(2, 4),
(2.5, 5),
(5, 5),
(10, 5)]

# This test is meant to verify the parameterization for
# test_number_of_minor_ticks
def test_using_all_default_major_steps(self):
with matplotlib.rc_context({'_internal.classic_mode': False}):
majorsteps = [x[0] for x in self.majorstep_minordivisions]
assert np.allclose(majorsteps, mticker.AutoLocator()._steps)

@pytest.mark.parametrize('major_step, expected_nb_minordivisions',
majorstep_minordivisions)
def test_number_of_minor_ticks(
self, major_step, expected_nb_minordivisions):
fig, ax = plt.subplots()
xlims = (0, major_step)
ax.set_xlim(*xlims)
ax.set_xticks(xlims)
ax.minorticks_on()
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
nb_minor_divisions = len(ax.xaxis.get_minorticklocs()) + 1
assert nb_minor_divisions == expected_nb_minordivisions

limits = [(0, 1.39), (0, 0.139),
(0, 0.11e-19), (0, 0.112e-12),
(-2.0e-07, -3.3e-08), (1.20e-06, 1.42e-06),
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2620,8 +2620,10 @@ def __call__(self):
return []

if self.ndivs is None:
x = int(np.round(10 ** (np.log10(majorstep) % 1)))
if x in [1, 5, 10]:

majorstep_no_exponent = 10 ** (np.log10(majorstep) % 1)

if np.isclose(majorstep_no_exponent, [1.0, 2.5, 5.0, 10.0]).any():
ndivs = 5
else:
ndivs = 4
Expand Down
0