Seaborn FacetGrid:在映射 stripplot 闪避时未实现

Seaborn FacetGrid: while mapping a stripplot dodge not implemented

我正在尝试使用 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)

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

虽然实现了大部分关键字,但色调没有被闪避。

我用另一种方法成功了:

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)

这给出了正确的输出:

在这个输出中,色调被减淡了。

我的问题是:为什么g.map(sns.stripplot...)没有闪避色相?

hue 参数需要通过 g.map 映射到 sns.stripplot 函数,而不是设置为 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)

这是因为 maptime 列中的每个值单独调用 sns.stripplot,并且如果为完整的 Facetgrid 指定了 hue ,对于每个色调值,这样 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

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