Skip to content

Commit 1f2b089

Browse files
jklymakMeeseeksDev[bot]
authored andcommitted
Backport PR #11762: fix minor grid overlapping
1 parent 2ae3b7a commit 1f2b089

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
@@ -76,7 +76,7 @@ def test_basic(self):
7676
ax.minorticks_on()
7777
test_value = np.array([0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45,
7878
0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9,
79-
0.95, 1, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
79+
0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
8080
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
8181

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

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

103150
class TestLogLocator(object):
104151
def test_basic(self):

lib/matplotlib/ticker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,8 +2555,10 @@ def __call__(self):
25552555
tmin = ((vmin - t0) // minorstep + 1) * minorstep
25562556
tmax = ((vmax - t0) // minorstep + 1) * minorstep
25572557
locs = np.arange(tmin, tmax, minorstep) + t0
2558-
cond = np.abs((locs - t0) % majorstep) > minorstep / 10.0
2559-
locs = locs.compress(cond)
2558+
mod = np.abs((locs - t0) % majorstep)
2559+
cond1 = mod > minorstep / 10.0
2560+
cond2 = ~np.isclose(mod, majorstep, atol=0)
2561+
locs = locs.compress(cond1 & cond2)
25602562

25612563
return self.raise_if_exceeds(np.array(locs))
25622564

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