2017-09-09 17 views
1

Seaborn을 사용하여 각 하위 플롯에서 스트립 폿을 표시하는 factorplot을 생성하려고합니다. 스트립 포토에서 마커의 몇 가지 측면을 제어하고 싶습니다.Seaborn FacetGrid : stripplot 닷지를 매핑하는 동안 구현되지 않았습니다

여기 내가 시도한 첫 번째 방법입니다 :

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...)이 색조를 왜 피하지 않았습니까?

답변

0

hue 파라미터 대신에 Facetgridhue로 설정되는 상기 g.map 통해 sns.stripplot 기능에 맵핑 될 필요가있다.

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

그 이유 dodge은 그 의미를 잃어 버릴 것 같은 것을 map 통화 개별적으로 time 열의 각 값에 대한 sns.stripplot하고, hue 경우 각 색상 값에 대해, 전체 Facetgrid 지정되어, 각 개별 통화에 대해

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 

솔직히이 우리에게 말하고 있는지 모르겠어요; 하지만 지금은 솔루션을 손상시키지 않는 것 같습니다.