【发布时间】:2019-05-13 00:15:58
【问题描述】:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
sns.set(style="darkgrid")
g = sns.scatterplot(x="Area", y="Rent/Sqft", hue="region", style="availability", data=df)
当我运行它时,我得到下面的情节。
我想将图例移到情节之外。我用谷歌搜索并尝试了以下
g.legend(loc='right', bbox_to_anchor=(1.25, 0.5), ncol=1)
plt.show()
但我没有得到任何输出。此外,我无法理解对象 plt 是如何连接到我的 sns 对象的
我正在使用 Jupyter Notebook、Python 3.6 和 Seaborn 0.9.0。
【问题讨论】:
-
也许你更愿意使用
ax.legend(loc='center left', bbox_to_anchor=(1.02, 0.5), ncol=1),但它对我来说很好用。你能更详细地解释一下“但我没有得到任何输出”吗?是什么意思?
标签: python matplotlib seaborn scatter-plot