keyword - Seaborn FacetGrid : while mapping a stripplot dodge not implemented

标签 keyword seaborn facet-grid

使用 Seaborn,我尝试生成一个因子图,其中每个子图都显示一个带状图。在带状图中,我想控制标记的几个方面。

这是我尝试的第一种方法:

import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time",  hue="smoker")
g = g.map(sns.stripplot, 'day', "tip", edgecolor="black", 
          linewideth=1, dodge=True, jitter=True, size=10)

并在没有闪避的情况下产生以下输出

output no dodge

虽然大多数关键字都已实现,但色调并未被回避。

我用另一种方法取得了成功:

kws = dict(s=10, linewidth=1, edgecolor="black")
tips = sns.load_dataset("tips")
sns.factorplot(x='day', y='tip', hue='smoker', col='time', data=tips,
          kind='strip',jitter=True, dodge=True, **kws, legend=False)

这给出了正确的输出: correct output

在此输出中,色调被躲避。

我的问题是:为什么g.map(sns.stripplot...)不躲避色调?

最佳答案

hue参数需要映射到sns.stripplot通过g.map功能,而不是设置为 hueFacetgrid

import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time")
g = g.map(sns.stripplot, 'day', "tip", "smoker", edgecolor="black", 
          linewidth=1, dodge=True, jitter=True, size=10)

enter image description here

这是因为map来电 sns.stripplot分别针对 time 中的每个值列,并且,如果 hue指定为完整的Facetgrid ,对于每个色调值,这样 dodge在每个单独的调用中都会失去其含义。

我同意这种行为不是很直观,除非您查看 source code of map 本身。

请注意,上述解决方案会导致警告:

lib\site-packages\seaborn\categorical.py:1166: FutureWarning:elementwise comparison failed;
   returning scalar instead, but in the future will perform elementwise comparison
  hue_mask = self.plot_hues[i] == hue_level

老实说,我不知道这告诉我们什么;但目前似乎不会破坏解决方案。

关于keyword - Seaborn FacetGrid : while mapping a stripplot dodge not implemented,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46134282/

相关文章:

python - 如何使用 matplotlib 或 seaborn 在两行中绘制 5 个子图?

python - 包裹时如何防止seaborn FacetGrid重叠

python - Seaborn FacetGrid,如何在所有子图中显示 y 刻度标签

r - ggplot - 集中 facet_grid 标题并且只出现一次

python - 有没有办法在 Python 中导入以关键字命名的文件?

Python 命名参数是关键字?

python - Seaborn 多轴图将不同颜色分配给相同/共享类别色调

java - 在类的唯一现有构造函数中创建对 "this"的引用

C++:定义类函数的 .cpp 文件中实例本身的表示关键字

python - 在 seaborn 中使用 FacetGrid 为所有面重复 x 轴标签