Skip to content

Commit 483b78f

Browse files
fix minor grid overlapping
1 parent 250c33e commit 483b78f

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_basic(self):
7474
ax.minorticks_on()
7575
test_value = np.array([0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45,
7676
0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9,
77-
0.95, 1, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
77+
0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
7878
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
7979

8080
# NB: the following values are assuming that *xlim* is [0, 5]
@@ -97,6 +97,53 @@ def test_low_number_of_majorticks(
9797
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
9898
assert len(ax.xaxis.get_minorticklocs()) == expected_nb_minorticks
9999

100+
limits = [(0, 1.39), (0, 0.139),
101+
(0, 0.11e-19), (0, 0.11e-12),
102+
(-2.0e-07, -3.3e-08), (1.20e-06, 1.42e-06),
103+
(-1.34e-06, -1.44e-06), (-8.76e-07, -1.51e-06)]
104+
105+
reference = [
106+
[0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.65, 0.7,
107+
0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35],
108+
[0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, 0.05, 0.055, 0.065,
109+
0.07, 0.075, 0.085, 0.09, 0.095, 0.105, 0.11, 0.115, 0.125, 0.13,
110+
0.135],
111+
[5.00e-22, 1.00e-21, 1.50e-21, 2.50e-21, 3.00e-21, 3.50e-21, 4.50e-21,
112+
5.00e-21, 5.50e-21, 6.50e-21, 7.00e-21, 7.50e-21, 8.50e-21, 9.00e-21,
113+
9.50e-21, 1.05e-20, 1.10e-20],
114+
[5.00e-15, 1.00e-14, 1.50e-14, 2.50e-14, 3.00e-14, 3.50e-14, 4.50e-14,
115+
5.00e-14, 5.50e-14, 6.50e-14, 7.00e-14, 7.50e-14, 8.50e-14, 9.00e-14,
116+
9.50e-14, 1.05e-13],
117+
[-1.95e-07, -1.90e-07, -1.85e-07, -1.75e-07, -1.70e-07, -1.65e-07,
118+
-1.55e-07, -1.50e-07, -1.45e-07, -1.35e-07, -1.30e-07, -1.25e-07,
119+
-1.15e-07, -1.10e-07, -1.05e-07, -9.50e-08, -9.00e-08, -8.50e-08,
120+
-7.50e-08, -7.00e-08, -6.50e-08, -5.50e-08, -5.00e-08, -4.50e-08,
121+
-3.50e-08],
122+
[1.21e-06, 1.22e-06, 1.23e-06, 1.24e-06, 1.26e-06, 1.27e-06, 1.28e-06,
123+
1.29e-06, 1.31e-06, 1.32e-06, 1.33e-06, 1.34e-06, 1.36e-06, 1.37e-06,
124+
1.38e-06, 1.39e-06, 1.41e-06, 1.42e-06],
125+
[-1.435e-06, -1.430e-06, -1.425e-06, -1.415e-06, -1.410e-06,
126+
-1.405e-06, -1.395e-06, -1.390e-06, -1.385e-06, -1.375e-06,
127+
-1.370e-06, -1.365e-06, -1.355e-06, -1.350e-06, -1.345e-06],
128+
[-1.48e-06, -1.46e-06, -1.44e-06, -1.42e-06, -1.38e-06, -1.36e-06,
129+
-1.34e-06, -1.32e-06, -1.28e-06, -1.26e-06, -1.24e-06, -1.22e-06,
130+
-1.18e-06, -1.16e-06, -1.14e-06, -1.12e-06, -1.08e-06, -1.06e-06,
131+
-1.04e-06, -1.02e-06, -9.80e-07, -9.60e-07, -9.40e-07, -9.20e-07,
132+
-8.80e-07]]
133+
134+
additional_data = list(zip(limits, reference))
135+
136+
@pytest.mark.parametrize('lim, ref', additional_data)
137+
def test_additional(self, lim, ref):
138+
fig, ax = plt.subplots()
139+
140+
ax.minorticks_on()
141+
ax.grid(True, 'minor', 'y', linewidth=1)
142+
ax.grid(True, 'major', color='k', linewidth=1)
143+
ax.set_ylim(lim)
144+
145+
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref)
146+
100147

101148
class TestLogLocator(object):
102149
def test_basic(self):

lib/matplotlib/ticker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,8 +2535,10 @@ def __call__(self):
25352535
tmin = ((vmin - t0) // minorstep + 1) * minorstep
25362536
tmax = ((vmax - t0) // minorstep + 1) * minorstep
25372537
locs = np.arange(tmin, tmax, minorstep) + t0
2538-
cond = np.abs((locs - t0) % majorstep) > minorstep / 10.0
2539-
locs = locs.compress(cond)
2538+
mod = np.abs((locs - t0) % majorstep)
2539+
cond1 = mod > minorstep / 10.0
2540+
cond2 = ~np.isclose(mod, majorstep, atol=0)
2541+
locs = locs.compress(cond1 & cond2)
25402542

25412543
return self.raise_if_exceeds(np.array(locs))
25422544

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy