python - Seaborn FacetGrid KDE 值错误
问题描述
我sns.FacetGrid
在 seaborn 的几个核密度图( )中做一个平面网格( sns.kdeplot
)并运行这个代码:
import pandas as pd
import seaborn as sns
data = sns.load_dataset('exercise')
g = sns.FacetGrid(data=data, col='diet')
g.map(sns.kdeplot,'pulse',hue='kind')
导致此错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/MislabelUnc/compare/debugsns.py in
11 g = sns.FacetGrid(data=data, col='diet')
----> 12 g.map(sns.kdeplot,'pulse',hue='kind')
~/anaconda3/envs/plot/lib/python3.9/site-packages/seaborn/axisgrid.py in map(self, func, *args, **kwargs)
681
682 # Draw the plot
--> 683 self._facet_plot(func, ax, plot_args, kwargs)
684
685 # Finalize the annotations and layout
~/anaconda3/envs/plot/lib/python3.9/site-packages/seaborn/axisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
773 plot_args = []
774 plot_kwargs["ax"] = ax
--> 775 func(*plot_args, **plot_kwargs)
776
777 # Sort out the supporting information
~/anaconda3/envs/plot/lib/python3.9/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
44 )
45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46 return f(**kwargs)
47 return inner_f
48
~/anaconda3/envs/plot/lib/python3.9/site-packages/seaborn/distributions.py in kdeplot(x, y, shade, vertical, kernel, bw, gridsize, cut, clip, legend, cumulative, shade_lowest, cbar, cbar_ax, cbar_kws, ax, weights, hue, palette, hue_order, hue_norm, multiple, common_norm, common_grid, levels, thresh, bw_method, bw_adjust, log_scale, color, fill, data, data2, **kwargs)
1694 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
1695
-> 1696 p = _DistributionPlotter(
1697 data=data,
1698 variables=_DistributionPlotter.get_semantics(locals()),
~/anaconda3/envs/plot/lib/python3.9/site-packages/seaborn/distributions.py in __init__(self, data, variables)
107 ):
108
--> 109 super().__init__(data=data, variables=variables)
110
111 @property
~/anaconda3/envs/plot/lib/python3.9/site-packages/seaborn/_core.py in __init__(self, data, variables)
602 def __init__(self, data=None, variables={}):
603
--> 604 self.assign_variables(data, variables)
605
606 for var, cls in self._semantic_mappings.items():
~/anaconda3/envs/plot/lib/python3.9/site-packages/seaborn/_core.py in assign_variables(self, data, variables)
665 else:
666 self.input_format = "long"
--> 667 plot_data, variables = self._assign_variables_longform(
668 data, **variables,
669 )
~/anaconda3/envs/plot/lib/python3.9/site-packages/seaborn/_core.py in _assign_variables_longform(self, data, **kwargs)
900
901 err = f"Could not interpret value `{val}` for parameter `{key}`"
--> 902 raise ValueError(err)
903
904 else:
ValueError: Could not interpret value `kind` for parameter `hue`
我不知道是什么原因造成的,因为
sns.kdeplot(data=data, x='pulse', hue='kind')
工作得很好。
我究竟做错了什么?
解决方案
推荐阅读
- asp.net - 如何更改在 Visual Studio 代码中启动 asp.net web api 的浏览器?
- android - 导航组件异常“已添加片段”
- c++ - 类的 C++ 模板
- c++ - 通过复制 Abseil 示例使用 STL 实现工厂功能
- python - Python3 | 安装程序 | 如何将excel文件添加到exe
- linux - 如何创建仅包含部分特定路径的 tarball
- spring - Quarkus 框架是从 Spring 框架的核心创建的?
- python-3.x - *args 在 list() 函数的情况下如何工作?
- html - 当我在其他 div 中有 div 时,我不能让它们粘在顶部或底部
- node.js - IntelliJ:使用 jest 和 Vue.js2 在断点处停止执行单个文件组件