def set_bandwidth(self, bw_method=None):
if bw_method is None:<EOL><INDENT>pass<EOL><DEDENT>elif bw_method == '<STR_LIT>':<EOL><INDENT>self.covariance_factor = self.scotts_factor<EOL><DEDENT>elif bw_method == '<STR_LIT>':<EOL><INDENT>self.covariance_factor = self.silverman_factor<EOL><DEDENT>elif np.isscalar(bw_method) and not isinstance(bw_method, string_types):<EOL><INDENT>self._bw_method = '<STR_LIT>'<EOL>self.covariance_factor = lambda: bw_method<EOL><DEDENT>elif callable(bw_method):<EOL><INDENT>self._bw_method = bw_method<EOL>self.covariance_factor = lambda: self._bw_method(self)<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>""<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>self._compute_covariance()<EOL>
Compute the estimator bandwidth with given method.

        The new bandwidth calculated after a call to `set_bandwidth` is used
        for subsequent evaluations of the estimated density.

        Parameters
        ----------
        bw_method : str, scalar or callable, optional
            The method used to calculate the estimator bandwidth.  This can be
            'scott', 'silverman', a scalar constant or a callable.  If a
            scalar, this will be used directly as `kde.factor`.  If a callable,
            it should take a `gaussian_kde` instance as only parameter and
            return a scalar.  If None (default), nothing happens; the current
            `kde.covariance_factor` method is kept.

        Notes
        -----
        .. versionadded:: 0.11

        Examples
        --------
        >>> x1 = np.array([-7, -5, 1, 4, 5.])
        >>> kde = stats.gaussian_kde(x1)
        >>> xs = np.linspace(-10, 10, num=50)
        >>> y1 = kde(xs)
        >>> kde.set_bandwidth(bw_method='silverman')
        >>> y2 = kde(xs)
        >>> kde.set_bandwidth(bw_method=kde.factor / 3.)
        >>> y3 = kde(xs)

        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> ax.plot(x1, np.ones(x1.shape) / (4. * x1.size), 'bo',
        ...         label='Data points (rescaled)')
        >>> ax.plot(xs, y1, label='Scott (default)')
        >>> ax.plot(xs, y2, label='Silverman')
        >>> ax.plot(xs, y3, label='Const (1/3 * Silverman)')
        >>> ax.legend()
        >>> plt.show()