【发布时间】:2016-10-15 09:47:35
【问题描述】:
我想将 Seaborn 配对图图例移到散点图矩阵之外。官方docs不给关键字legend。我正在尝试同时在 3 个不同的位置绘制图例之外的图例:底部中心、顶部中心、右侧中心
我试过这个:
import matplotlib.pyplot as plt
import seaborn as sns
iris = sns.load_dataset("iris")
g = sns.pairplot(iris,hue='species', palette='husl', markers='d', size=2.5, plot_kws=
{
"s":40,
"alpha":1.0,
'lw':0.5,
'edgecolor':'k'
})
plt.legend(loc='upper center', bbox_to_anchor=(1.10, 1.0), ncol=1) #vertical legend
plt.legend(loc='lower center', bbox_to_anchor=(0.0, -0.15), ncol=3) #horizontal legend bottom
plt.legend(loc='upper left', bbox_to_anchor=(0.0, 1.15), ncol=3) #horizontal legend top
g.savefig('Test.png', bbox_inches='tight')
所有 3 个图例都打印不正确。我不确定它是否在做我要求的定位。我不确定右边发生了什么 - 似乎出现了 2 个垂直图例,并且由于某种原因它们完全相互重叠。两个横向图例之一根本没有出现。
有没有办法避免垂直图例重叠,并将图例放在图外的 3 个位置 - 顶部中心、底部中心、右中心?
【问题讨论】:
-
默认位置是垂直方向在右侧外侧,如 here 所示。但是,必须有一种方法可以在这三个位置之一绘制图例。这里有什么建议吗?
标签: python python-2.7 matplotlib seaborn