Skip to content

Commit 9ca82e1

Browse files
committed
TST: fix log tests
1 parent fba2dc3 commit 9ca82e1

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

lib/matplotlib/contour.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1201,11 +1201,20 @@ def _autolev(self, N):
12011201
pass
12021202

12031203
# Trim excess levels the locator may have supplied.
1204-
rtol = (self.zmin - self.zmax) * 1e-10
1205-
under = np.nonzero(lev < self.zmin - rtol)[0]
1204+
1205+
levt = lev
1206+
zmin = self.zmin
1207+
zmax = self.zmax
1208+
# tolerances need to be in log space if we are a logscale....
1209+
if self.logscale:
1210+
levt = np.log10(levt)
1211+
zmin = np.log10(zmin)
1212+
zmax = np.log10(zmax)
1213+
rtol = (zmin - zmax) * 1e-10
1214+
under = np.nonzero(levt < zmin - rtol)[0]
12061215
i0 = under[-1] if len(under) else 0
1207-
over = np.nonzero(lev > self.zmax + rtol)[0]
1208-
i1 = over[0] + 1 if len(over) else len(lev)
1216+
over = np.nonzero(levt > zmax + rtol)[0]
1217+
i1 = over[0] + 1 if len(over) else len(levt)
12091218
# put back extra levels if we want to extend...
12101219
if self.extend in ('min', 'both'):
12111220
i0 += 1

lib/matplotlib/tests/test_contour.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def test_contourf_decreasing_levels():
310310
def test_contourf_symmetric_locator():
311311
# github issue 7271
312312
z = np.arange(12).reshape((3, 4))
313-
locator = plt.MaxNLocator(nbins=4, symmetric=True)
313+
locator = plt.MaxNLocator(nbins=4, symmetric=True, trim_outside=False)
314314
cs = plt.contourf(z, locator=locator)
315315
assert_array_almost_equal(cs.levels, np.linspace(-12, 12, 5))
316316

lib/matplotlib/ticker.py

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ def _keep_in_vlim(locs, vmin, vmax, rtol=1e-10):
198198
vmax, vmin = vmin, vmax
199199

200200
rtol = (vmax - vmin) * rtol
201-
print(vmin, rtol)
202201
locs = locs[locs >= vmin - rtol]
203202
locs = locs[locs <= vmax + rtol]
204203
return locs

0 commit comments

Comments
 (0)