Repository: matplotlib/matplotlib
File: lib/matplotlib/contour.py (Python)

Code before:
        self.set_array(self.cvalues)
        self.update_scalarmappable()
        alphas = np.broadcast_to(self.get_alpha(), len(self.cvalues))
        for label, cv, alpha in zip(self.labelTexts, self.labelCValues, alphas):
            label.set_alpha(alpha)
            label.set_color(self.labelMappable.to_rgba(cv))
        super().changed()

    def _autolev(self, N):
        """
        Select contour levels to span the data.

        The target number of levels, *N*, is used only when the
        locator is not set and the scale is log or the default
        locator is used.

        We need two more levels for filled contours than for
        line contours, because for the latter we need to specify
        the lower and upper boundary of each range. For example,
        a single contour boundary, say at z = 0, requires only
        one contour line, but two filled regions, and therefore
        three levels to provide boundaries for both regions.

        Parameters
        ----------
        N : int | None
        """
        if self.locator is None:
            if self.logscale:
                if N is None:
                    self.locator = ticker.LogLocator()
                else:
                    self.locator = ticker.LogLocator(numticks=N)
            else:
                if N is None:
                    N = 7  # Hard coded default
                self.locator = ticker.MaxNLocator(N + 1, min_n_ticks=1)

        lev = self.locator.tick_values(self.zmin, self.zmax)

        try:
            if self.locator._symmetric:
                return lev
        except AttributeError:
            pass

        # Trim excess levels the locator may have supplied.
        under = np.nonzero(lev < self.zmin)[0]
        i0 = under[-1] if len(under) else 0
        over = np.nonzero(lev > self.zmax)[0]
        i1 = over[0] + 1 if len(over) else len(lev)

Review comment (suggestion):
```suggestion
        N : int or None
```
to stay in the numpydoc convention.

Code after:
        self.set_array(self.cvalues)
        self.update_scalarmappable()
        alphas = np.broadcast_to(self.get_alpha(), len(self.cvalues))
        for label, cv, alpha in zip(self.labelTexts, self.labelCValues, alphas):
            label.set_alpha(alpha)
            label.set_color(self.labelMappable.to_rgba(cv))
        super().changed()

    def _ensure_locator_exists(self, N):
        """
        Set a locator on this ContourSet if it's not already set.

        Parameters
        ----------
        N : int or None
            If *N* is an int, it is used as the target number of levels.
            Otherwise when *N* is None, a reasonable default is chosen;
            for logscales the LogLocator chooses, N=7 is the default
            otherwise.
        """
        if self.locator is None:
            if self.logscale:
                self.locator = ticker.LogLocator(numticks=N)
            else:
                if N is None:
                    N = 7  # Hard coded default
                self.locator = ticker.MaxNLocator(N + 1, min_n_ticks=1)

    def _autolev(self):
        """
        Select contour levels to span the data.

        We need two more levels for filled contours than for
        line contours, because for the latter we need to specify
        the lower and upper boundary of each range. For example,
        a single contour boundary, say at z = 0, requires only
        one contour line, but two filled regions, and therefore
        three levels to provide boundaries for both regions.
        """
        lev = self.locator.tick_values(self.zmin, self.zmax)

        try:
            if self.locator._symmetric:
                return lev
        except AttributeError:
            pass

        # Trim excess levels the locator may have supplied.
        under = np.nonzero(lev < self.zmin)[0]
        i0 = under[-1] if len(under) else 0
        over = np.nonzero(lev > self.zmax)[0]