我将 factorplot(kind="bar")
与 seaborn 一起使用。
情节很好,只是图例放错了位置:太靠右了,文字超出了情节的阴影区域。
如何让 seaborn 将图例放置在其他位置,例如左上角而不是右中角?
最佳答案
基于@user308827 的回答:您可以在 factorplot 中使用 legend=False
并通过 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")
plt
作用于当前坐标区。要从FacetGrid
获取坐标轴,请使用 fig。g.fig.get_axes()[0].legend(loc='lower left')
关于python - 将 seaborn 情节图例移动到不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27019079/