2017-11-21 3 views
0

lmplotを設定すると、各変数に異なる色相を持つだけでなく、別のマーカーも同様に設定できますか?lmplot seabornの色相ごとに異なるマーカー

たとえば、これらのポイントに属する「カテゴリ」に基づいて、どのように異なるマーカーを得ることができますか?

import pandas as pd 
import seaborn as sns 
dic={"A":[4,6,5], "B":[2,7,5], "category":['A','A',"B"]} 
df=pd.DataFrame(dic) 
sns.lmplot('A', 'B', data=df, hue='category', fit_reg=False)] 

私は、次のような、リストITERに合格しようとしている:

marker_cycle=['o', 'x', '^'] 
[next(marker_cycle) for i in df["category"].unique() 

が、成功していません。

答えて

1

sns.lmplot

sns.lmplot('A', 'B', data=df, hue='category', fit_reg=False,markers=['o', 'x']) 

enter image description here

0

を参照してくださいthis issue内部markersがあります。 next()はイテレータで作業する必要があります。あなたは、intertoolsと1作成することができ

import itertools 
mks = itertools.cycle(['o', 'x', '^', '+', '*', '8', 's', 'p', 'D', 'V']) 
markers = [next(mks) for i in df["category"].unique()] 

例:

これは少しやり過ぎていてもよく、あなたは、単に直接リストfromtマーカーを得ることができることを
import pandas as pd 
import seaborn as sns 
import matplotlib.pyplot as plt 

dic={"A":[4,6,5], "B":[2,7,5], "category":['A','A',"B"]} 
df=pd.DataFrame(dic) 

import itertools 
mks = itertools.cycle(['o', 'x', '^', '+', '*', '8', 's', 'p', 'D', 'V']) 
markers = [next(mks) for i in df["category"].unique()] 

sns.lmplot('A', 'B', data=df, hue='category', markers=markers, fit_reg=False) 

plt.show() 

注意、

marker = ['o', 'x', '^', '+', '*', '8', 's', 'p', 'D', 'V'] 
markers = [marker[i] for i in range(len(df["category"].unique()))] 

完全な例:

import pandas as pd 
import seaborn as sns 
import matplotlib.pyplot as plt 

dic={"A":[4,6,5], "B":[2,7,5], "category":['A','A',"B"]} 
df=pd.DataFrame(dic) 

marker = ['o', 'x', '^', '+', '*', '8', 's', 'p', 'D', 'V'] 
markers = [marker[i] for i in range(len(df["category"].unique()))] 

sns.lmplot('A', 'B', data=df, hue='category', markers=markers, fit_reg=False) 

plt.show() 
0123同じプロットで上記結果からの

両溶液:

enter image description here

関連する問題