2016-05-19 9 views
0

私はこのコードが作成するプロットは、私が作成したいどのような積み重ねられたプロット enter image description here あるこのquesitionためSeaborn Facetgridのcountplot色相

import pandas as pd 
from pandas import DataFrame 
import seaborn as sns 
import numpy as np 


sex = np.array(['Male','Female']) 
marker1 = np.array(['Absent','Present']) 
marker2 = np.array(['Absent','Present']) 

sample1 = np.random.randint(0,2,100) 
sample2 = np.random.randint(0,2,100) 
sample3 = np.random.randint(0,2,100) 

df=pd.concat([pd.Series(sex.take(sample1),dtype='category'),pd.Series(marker1.take(sample2),dtype='category'),pd.Series(marker2.take(sample3),dtype='category')],axis=1) 

df.rename(columns={0:'Sex',1:'Marker1',2:'Marker2'},inplace=True) 

fig =sns.FacetGrid(data=df,col='Sex',hue='Marker2',palette='Set1',size=4,aspect=1).map(sns.countplot,'Marker1',order=df.Marker1.unique()).add_legend() 

をサンプルデータセットを作成しているが(R)からかわすプロットです。どのようにしてこのコードを修正して、私がのサイドバイサイド比較を見ることができるかMarker2存在感?

+1

'factorplot'を使用してください。 – mwaskom

+0

@mwaskom '' 'factorplot'''は私にTypeErrorを与えます。エラーは '' 'TypeError:タイプ 'NoneType'のオブジェクトにはlen()' 'がありません –

+0

あなたがしたことを知らずにエラーの原因を言うのは難しいです。 – mwaskom

答えて

0

私は同じ問題を抱えていました。

sns.countplotコールのラッパー関数を記述するだけでFacetGridコマンドを使用できます。

def countplot(x, hue, **kwargs): 
    sns.countplot(x=x, hue=hue, **kwargs) 

grid = sns.FacetGrid(data=df,col='Sex',size=4,aspect=1) 
fig = grid.map(countplot,'Marker1','Marker2',palette='Set1',order=df.Marker1.unique()) 
fig.add_legend() 
関連する問題