【发布时间】:2016-02-22 19:48:16
【问题描述】:
我尝试了来自 previous question 的答案,但在 Matplotlib 1.5.1 中无济于事。
我有一个海底人物:
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
tips = sns.load_dataset("tips")
g = sns.jointplot("total_bill", "tip", data = tips[["total_bill", "tip"]].applymap(lambda x : -np.log10(x)))
这不起作用:
g.ax_joint.legend(loc = 'lower right')
还有这个:
plt.legend(bbox_to_anchor=(1.05, 1), loc=4, borderaxespad=0.)
/usr/local/lib/python3.4/dist-packages/matplotlib/axes/_axes.py:520: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
warnings.warn("No labelled objects found. "
在这种情况下,如何将现有图例定位到右下方?
目前不是一个优雅的解决方案:
ll = g.ax_joint.get_legend().get_texts()[0]._text
g.ax_joint.get_legend().remove()
g.ax_joint.text( -12, -12, ll, fontsize=14)
不过,我相信应该有更好的办法。
【问题讨论】:
-
在 MatPlotLib 文档页面上有一些示例,matplotlib.org/users/legend_guide.html
-
有一些例子,但是如果我不向艺术家提供句柄,例如`loc=4`在我的情况下没有效果。如果是seaborn,我找不到我需要的把手。如果您知道如何获取它们,请分享。
标签: python matplotlib seaborn