Skip to content

Commit 32b3210

Browse files
committed
Contour level auto-selection: clip unused Locator output
Locator.tick_values() returns levels beyond the data limits. In the case of LogLocator with a small data range, the overrun can be large because it is expanding to the decade points. In addition, no account was being taken of the "extend" kwarg. With this changeset, the outermost levels will be the miminum required to include the data interval in the default case, and will be reduced when "extend" is used so that some of the data range will fall in the extended sections. This is expected to be rare, however; normally the "extend" kwarg would be used only when levels are explicitly set, not auto-selected with a Locator.
1 parent 8064a81 commit 32b3210

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/matplotlib/contour.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,16 @@ def _autolev(self, N):
11871187
self.locator = ticker.MaxNLocator(N + 1, min_n_ticks=1)
11881188

11891189
lev = self.locator.tick_values(self.zmin, self.zmax)
1190+
i0 = np.nonzero(lev < self.zmin)[0][-1]
1191+
i1 = np.nonzero(lev > self.zmax)[0][0] + 1
1192+
if self.extend in ('min', 'both'):
1193+
i0 += 1
1194+
if self.extend in ('max', 'both'):
1195+
i1 -= 1
1196+
i1 = min(i1, len(lev))
1197+
11901198
self._auto = True
1191-
return lev
1199+
return lev[i0:i1]
11921200

11931201
def _contour_level_args(self, z, args):
11941202
"""

0 commit comments

Comments
 (0)