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

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

解决问题


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


相关文章
|
4月前
|
API C++ Python
【Azure 应用服务】Python fastapi Function在Azure中遇见AttributeError异常(AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async')
【Azure 应用服务】Python fastapi Function在Azure中遇见AttributeError异常(AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async')
|
5月前
|
并行计算 Serverless API
函数计算操作报错合集之出现 "AttributeError: 'NoneType' object has no attribute 'pop'" 错误,是什么原因
在使用函数计算服务(如阿里云函数计算)时,用户可能会遇到多种错误场景。以下是一些常见的操作报错及其可能的原因和解决方法,包括但不限于:1. 函数部署失败、2. 函数执行超时、3. 资源不足错误、4. 权限与访问错误、5. 依赖问题、6. 网络配置错误、7. 触发器配置错误、8. 日志与监控问题。
163 1
|
5月前
|
数据处理 API 索引
【Python】已解决:AttributeError: ‘Series‘ object has no attribute ‘sortlevel‘
【Python】已解决:AttributeError: ‘Series‘ object has no attribute ‘sortlevel‘
201 4
|
7月前
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
656 0
|
5月前
|
Python
【Python】已解决:(Python xlwt写入Excel报错)AttributeError: ‘function’ object has no attribute ‘font’
【Python】已解决:(Python xlwt写入Excel报错)AttributeError: ‘function’ object has no attribute ‘font’
122 0
|
5月前
|
XML 数据格式 Python
【Python】已解决:AttributeError: ‘function’ object has no attribute ‘ELement’
【Python】已解决:AttributeError: ‘function’ object has no attribute ‘ELement’
178 0
|
5月前
|
API Python
【Python】已解决:AttributeError: ‘TfidfVectorizer’ object has no attribute ‘get_feature_names_out’
【Python】已解决:AttributeError: ‘TfidfVectorizer’ object has no attribute ‘get_feature_names_out’
150 0
|
5月前
|
API 索引 Python
【Pandas】已完美解决:AttributeError: ‘DataFrame‘ object has no attribute ‘ix‘
【Pandas】已完美解决:AttributeError: ‘DataFrame‘ object has no attribute ‘ix‘
302 0
|
6月前
|
Python
【已解决】AttributeError: ‘Index‘ object has no attribute ‘to_list‘
【已解决】AttributeError: ‘Index‘ object has no attribute ‘to_list‘
|
7月前
|
安全 计算机视觉 Python
【已解决】attributeerror: ‘FreeTypeFont‘ object has no attribute ‘getsize‘
【已解决】attributeerror: ‘FreeTypeFont‘ object has no attribute ‘getsize‘