2017-04-01 247 views

回答

4

這可能是一個哈克解決方案,但它的工作原理:如果你告訴Seaborn離開它關閉在繪製的時間,然後將其重新添加它並沒有傳說標題:

g = sns.factorplot(x='Age Group',y='ED',hue='Became Member',col='Coverage Type', 
        col_wrap=3,data=gdf,kind='bar',ci=None,legend=False,palette='muted') 
#               ^^^^^^^^^^^^ 
plt.suptitle('ED Visit Rate per 1,000 Members per Year',size=16) 
plt.legend(loc='best') 
plt.subplots_adjust(top=.925) 
plt.show() 

範例結果:

enter image description here

+0

美麗。順便說一下,它也適用於熊貓 – famargar

+1

@famargar:謝謝你告訴我:-)快樂的編碼給你! – bernie

4

甲少哈克的方式是使用matplotlib的面向對象接口。通過獲取對軸的控制,它將使定製圖更加容易。在 resulting_plot

0

如果你想傳說

import seaborn as sns 
import matplotlib.pyplot as plt 
sns.set(style="whitegrid") 

# Load the example Titanic dataset 
titanic = sns.load_dataset("titanic") 

# Draw a nested barplot to show survival for class and sex 
fig, ax = plt.subplots() 
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic, 
        size=6, kind="bar", palette="muted", ax=ax) 
sns.despine(ax=ax, left=True) 
ax.set_ylabel("survival probability") 
l = ax.legend() 
l.set_title('Whatever you want') 
fig.show() 

結果到了劇情軸線之外顯示,由於是默認factorplot,您可以使用FacetGrid.add_legendfactorplot返回FacetGrid實例)。其它方法讓你在FacetGrid一次

import seaborn as sns 
import matplotlib.pyplot as plt 
sns.set(style="whitegrid") 

# Load the example Titanic dataset 
titanic = sns.load_dataset("titanic") 

# Draw a nested barplot to show survival for class and sex 
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic, 
        size=6, kind="bar", palette="muted", legend=False) 
(g.despine(left=True) 
    .set_ylabels('survival probability') 
    .add_legend(title='Whatever you want') 
)