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

简介: 成功解决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函数中,即可!

1. 
2. def kdeplot Found at: seaborn.distributions
3. 
4. @_deprecate_positional_args
5. def kdeplot(
6.     x= # Allow positional x, because behavior will not change with reorg
7.     None, 
8.     *, y=None, 
9.     shade= # Note "soft" deprecation, explained below
10.     None, vertical= # Deprecated
11.     False, kernel= # Deprecated
12.     None, bw= # Deprecated
13.     None, gridsize= # TODO maybe depend on uni/bivariate?
14.     200, cut=3, clip=None, legend=True, cumulative=False, 
15.     shade_lowest= # Deprecated, controlled with levels now
16.     None, cbar=False, cbar_ax=None, cbar_kws=None, 
17.     ax=
18.     # New params
19.     None, weights= # TODO note that weights is grouped with 
20.      semantics
21.     None, hue=None, palette=None, hue_order=None, 
22.      hue_norm=None, 
23.     multiple="layer", common_norm=True, common_grid=False, 
24.     levels=10, thresh=.05, 
25.     bw_method="scott", bw_adjust=1, log_scale=None, 
26.     color=None, fill=
27.     # Renamed params
28.     None, data=None, data2=None, **
29.     kwargs):
30. # Handle deprecation of `data2` as name for y variable
31. if data2 is not None:
32.         y = data2
33. # If `data2` is present, we need to check for the `data` kwarg being
34. # used to pass a vector for `x`. We'll reassign the vectors and 
35.          warn.
36. # We need this check because just passing a vector to `data` is 
37.          now
38. # technically valid.
39.         x_passed_as_data = x is None and data is not None and np.ndim
40.          (data) == 1
41. if x_passed_as_data:
42.             msg = "Use `x` and `y` rather than `data` `and `data2`"
43.             x = data
44. else:
45.             msg = "The `data2` param is now named `y`; please update your 
46.              code"
47.         warnings.warn(msg, FutureWarning)
48. # Handle deprecation of `vertical`
49. if vertical:
50.         msg = "The `vertical` parameter is deprecated and will be 
51.          removed in a "\
52. "future version. Assign the data to the `y` variable instead."
53.         warnings.warn(msg, FutureWarning)
54.         x, y = y, x
55. # Handle deprecation of `bw`
56. if bw is not None:
57.         msg = "The `bw` parameter is deprecated in favor of 
58.          `bw_method` and "\
59. f"`bw_adjust`. Using {bw} for `bw_method`, but please "\
60. "see the docs for the new parameters and update your code."
61.         warnings.warn(msg, FutureWarning)
62.         bw_method = bw
63. # Handle deprecation of `kernel`
64. if kernel is not None:
65.         msg = "Support for alternate kernels has been removed. "\
66. "Using Gaussian kernel."
67.         warnings.warn(msg, UserWarning)
68. # Handle deprecation of shade_lowest
69. if shade_lowest is not None:
70. if shade_lowest:
71.             thresh = 0
72.         msg = "`shade_lowest` is now deprecated in favor of `thresh`. "\
73. f"Setting `thresh={thresh}`, but please update your code."
74.         warnings.warn(msg, UserWarning)
75. # Handle `n_levels`
76. # This was never in the formal API but it was processed, and 
77.      appeared in an
78. # example. We can treat as an alias for `levels` now and deprecate 
79.      later.
80.     levels = kwargs.pop("n_levels", levels)
81. # Handle "soft" deprecation of shade `shade` is not really the right
82. # terminology here, but unlike some of the other deprecated 
83.      parameters it
84. # is probably very commonly used and much hard to remove. This 
85. is therefore
86. # going to be a longer process where, first, `fill` will be introduced 
87. and
88. # be used throughout the documentation. In 0.12, when kwarg-only
89. # enforcement hits, we can remove the shade/shade_lowest out of 
90.      the
91. # function signature all together and pull them out of the kwargs. 
92.      Then we
93. # can actually fire a FutureWarning, and eventually remove.
94. if shade is not None:
95.         fill = shade
96. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
97.     p = _DistributionPlotter(
98.         data=data, 
99.         variables=_DistributionPlotter.get_semantics(locals()))
100.     p.map_hue(palette=palette, order=hue_order, norm=hue_norm)
101. if ax is None:
102.         ax = plt.gca()
103. # Check for a specification that lacks x/y data and return early
104. if not p.has_xy_data:
105. return ax
106. # Pack the kwargs for statistics.KDE
107.     estimate_kws = dict(bw_method=bw_method, 
108.         bw_adjust=bw_adjust, 
109.         gridsize=gridsize, 
110.         cut=cut, 
111.         clip=clip, 
112.         cumulative=cumulative)
113.     p._attach(ax, allowed_types=["numeric", "datetime"], 
114.      log_scale=log_scale)
115. if p.univariate:
116.         plot_kws = kwargs.copy()
117. if color is not None:
118.             plot_kws["color"] = color
119.         p.plot_univariate_density(multiple=multiple, 
120.          common_norm=common_norm, common_grid=common_grid, 
121.          fill=fill, legend=legend, estimate_kws=estimate_kws, **plot_kws)
122. else:
123.         p.plot_bivariate_density(common_norm=common_norm, fill=fill, 
124.          levels=levels, thresh=thresh, legend=legend, color=color, cbar=cbar, 
125.          cbar_ax=cbar_ax, cbar_kws=cbar_kws, estimate_kws=estimate_kws, 
126.          **kwargs)
127. return ax


 

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