成功解决AttributeError: ‘PathCollection‘ object has no property ‘n_levels‘ daiding

成功解决AttributeError: 'PathCollection' object has no property 'n_levels'


解决问题

AttributeError: 'PathCollection' object has no property 'n_levels'

解决思路

属性错误:“PathCollection”对象没有属性“n_levels”

解决方法

def scatter Found at: matplotlib.pyplot中并没有n_levels参数!很可能是代码写的有误,这个参数存在在中,如果必须使用n_levels参数,那么应该加到sns.kdeplot函数中,即可!


def kdeplot Found at: seaborn.distributions

@_deprecate_positional_args
def kdeplot(
    x= # Allow positional x, because behavior will not change with reorg
    None,
    *, y=None,
    shade= # Note "soft" deprecation, explained below
    None, vertical= # Deprecated
    False, kernel= # Deprecated
    None, bw= # Deprecated
    None, gridsize= # TODO maybe depend on uni/bivariate?
    200, cut=3, clip=None, legend=True, cumulative=False,
    shade_lowest= # Deprecated, controlled with levels now
    None, cbar=False, cbar_ax=None, cbar_kws=None,
    ax=
    # New params
    None, weights= # TODO note that weights is grouped with
     semantics
    None, hue=None, palette=None, hue_order=None,
     hue_norm=None,
    multiple="layer", common_norm=True, common_grid=False,
    levels=10, thresh=.05,
    bw_method="scott", bw_adjust=1, log_scale=None,
    color=None, fill=
    # Renamed params
    None, data=None, data2=None, **
    kwargs):
    # Handle deprecation of `data2` as name for y variable
    if data2 is not None:
        y = data2
        # If `data2` is present, we need to check for the `data` kwarg being
        # used to pass a vector for `x`. We'll reassign the vectors and
         warn.
        # We need this check because just passing a vector to `data` is
         now
        # technically valid.
        x_passed_as_data = x is None and data is not None and np.ndim
         (data) == 1
        if x_passed_as_data:
            msg = "Use `x` and `y` rather than `data` `and `data2`"
            x = data
        else:
            msg = "The `data2` param is now named `y`; please update your
             code"
        warnings.warn(msg, FutureWarning)
    # Handle deprecation of `vertical`
    if vertical:
        msg = "The `vertical` parameter is deprecated and will be
         removed in a "        "future version. Assign the data to the `y` variable instead."
        warnings.warn(msg, FutureWarning)
        x, y = y, x
    # Handle deprecation of `bw`
    if bw is not None:
        msg = "The `bw` parameter is deprecated in favor of
         `bw_method` and "        f"`bw_adjust`. Using {bw} for `bw_method`, but please "        "see the docs for the new parameters and update your code."
        warnings.warn(msg, FutureWarning)
        bw_method = bw
    # Handle deprecation of `kernel`
    if kernel is not None:
        msg = "Support for alternate kernels has been removed. "        "Using Gaussian kernel."
        warnings.warn(msg, UserWarning)
    # Handle deprecation of shade_lowest
    if shade_lowest is not None:
        if shade_lowest:
            thresh = 0
        msg = "`shade_lowest` is now deprecated in favor of `thresh`. "        f"Setting `thresh={thresh}`, but please update your code."
        warnings.warn(msg, UserWarning)
    # Handle `n_levels`
    # This was never in the formal API but it was processed, and
     appeared in an
    # example. We can treat as an alias for `levels` now and deprecate
     later.
    levels = kwargs.pop("n_levels", levels)
    # Handle "soft" deprecation of shade `shade` is not really the right
    # terminology here, but unlike some of the other deprecated
     parameters it
    # is probably very commonly used and much hard to remove. This
     is therefore
    # going to be a longer process where, first, `fill` will be introduced
     and
    # be used throughout the documentation. In 0.12, when kwarg-only
    # enforcement hits, we can remove the shade/shade_lowest out of
     the
    # function signature all together and pull them out of the kwargs.
     Then we
    # can actually fire a FutureWarning, and eventually remove.
    if shade is not None:
        fill = shade
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
    p = _DistributionPlotter(
        data=data,
        variables=_DistributionPlotter.get_semantics(locals()))
    p.map_hue(palette=palette, order=hue_order, norm=hue_norm)
    if ax is None:
        ax = plt.gca()
    # Check for a specification that lacks x/y data and return early
    if not p.has_xy_data:
        return ax
    # Pack the kwargs for statistics.KDE
    estimate_kws = dict(bw_method=bw_method,
        bw_adjust=bw_adjust,
        gridsize=gridsize,
        cut=cut,
        clip=clip,
        cumulative=cumulative)
    p._attach(ax, allowed_types=["numeric", "datetime"],
     log_scale=log_scale)
    if p.univariate:
        plot_kws = kwargs.copy()
        if color is not None:
            plot_kws["color"] = color
        p.plot_univariate_density(multiple=multiple,
         common_norm=common_norm, common_grid=common_grid,
         fill=fill, legend=legend, estimate_kws=estimate_kws, **plot_kws)
    else:
        p.plot_bivariate_density(common_norm=common_norm, fill=fill,
         levels=levels, thresh=thresh, legend=legend, color=color, cbar=cbar,
         cbar_ax=cbar_ax, cbar_kws=cbar_kws, estimate_kws=estimate_kws,
         **kwargs)
    return ax
(0)

相关推荐