将 seaborn 情节图例移动到不同的位置? [英] Move seaborn plot legend to a different position?
本文介绍了将 seaborn 情节图例移动到不同的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 factorplot(kind="bar")
与 seaborn 一起使用.
I'm using factorplot(kind="bar")
with seaborn.
情节很好,只是图例放错了位置:太靠右了,文本超出了情节的阴影区域.
The plot is fine except the legend is misplaced: too much to the right, text goes out of the plot's shaded area.
如何让 seaborn 将图例放置在其他位置,例如左上角而不是右中角?
How do I make seaborn place the legend somewhere else, such as in top-left instead of middle-right?
推荐答案
基于@user308827 的回答:您可以在 factorplot 中使用 legend=False
并通过 matplotlib 指定图例:
Building on @user308827's answer: you can use legend=False
in factorplot and specify the legend through matplotlib:
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot("class", "survived", "sex",
data=titanic, kind="bar",
size=6, palette="muted",
legend=False)
g.despine(left=True)
plt.legend(loc='upper left')
g.set_ylabels("survival probability")
这篇关于将 seaborn 情节图例移动到不同的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文