2016-04-16 38 views
5

私は以下のプロットをPythonとSeabornでfactorplot()メソッドを使ってビルドしています。右の線の色に基づいて凡例を置き換える凡例として線のスタイルを使用することは可能ですか? enter image description herePython Seaborn Matplotlibは凡例としてラインスタイルを設定します

graycolors = sns.mpl_palette('Greys_r', 4) 
g = sns.factorplot(x="k", y="value", hue="class", palette=graycolors, data=df, linestyles=["-", "--"]) 

さらに)私は私のfactorplot方法で色=「黒」パラメータを使用して、黒の色の両方の行を取得しようとしているが、これは例外「factorplot(その結果、予期しないキーワード引数 『色』を得ました"どのように私は同じ色で両方の線を塗りつぶし、ラインスタイルだけでそれらを分離することができますか?

答えて

3

ありがとう私はmatplotlibよう凡例に線種を入れしようとして解決策を探してきたが、私はまだseabornでこれを行う方法を発見していません。しかし、私は別のmarkersを使用していた伝説のデータを明確にします

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

# creating some data 
n = 11 
x = np.linspace(0,2,n) 
y = np.sin(2*np.pi*x) 
y2 = np.cos(2*np.pi*x) 
df=pd.DataFrame({'x':np.append(x, x),'y':np.append(y, y2),'class':np.append(np.repeat('sin',n),np.repeat('cos',n))}) 

# plot the data with the markers 
# note that I put the legend=False to move it up (otherwise it was blocking the graph) 
g=sns.factorplot(x="x",y="y",hue="class",palette=graycolors, data=df, linestyles=["-", "--"],markers=['o','v'], legend=False) 
# placing the legend up 
g.axes[0][0].legend(loc=1) 
#showing graph 
plt.show() 

the graph

+0

素晴らしい、ありがとう。まだ私に関係があります –

関連する問題