我用seaborn繪製一個分組柱狀圖在https://seaborn.pydata.org/examples/factorplot_bars.html刪除Seaborn barplot圖例標題
給予我: https://seaborn.pydata.org/_images/factorplot_bars.png
有關於這一點我想刪除圖例標題(性別)。
我怎麼能做到這一點?
我用seaborn繪製一個分組柱狀圖在https://seaborn.pydata.org/examples/factorplot_bars.html刪除Seaborn barplot圖例標題
給予我: https://seaborn.pydata.org/_images/factorplot_bars.png
有關於這一點我想刪除圖例標題(性別)。
我怎麼能做到這一點?
這可能是一個哈克解決方案,但它的工作原理:如果你告訴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()
範例結果:
如果你想傳說
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_legend
(factorplot
返回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')
)
您需要添加您正在使用的代碼調整各軸的標籤。 – Ali