‘嗨,我用海运创建了一个集群地图。因为传说和图形重叠,所以我想把它移开。然而,plt.legend(bbox_to_anchor=(1,1))给出了以下错误:“没有标签显示的句柄”。这让我想知道:我想重新定位的左上角20到20的颜色是多少?这不是个传说吗?谢谢你提前为我澄清了这一点。“”“
import matplotlib.pyplot as plt
import seaborn as sns
g = sns.clustermap(data=df_highestPivot,cmap='coolwarm')
plt.legend(bbox_to_anchor=(1,1)) #This line generate the error
plt.savefig('plot.png',dpi=300,bbox_to_inches='tight')
plt.show()
plt.close()

发布于 2020-07-13 19:22:40
颜色条本身不是一个图例(至少不是Legend类型的对象)。实际上,您可以使用g.ax_cbar访问它自己的子图轴。
如果要移动它,可以传递一个参数cbar_pos= to clustermap()。然而,在图形中找到一个空空间来放置它是很复杂的。我建议您使用subplots_adjust()腾出一些空间,然后将ax_cbar轴移到所需的位置
iris = sns.load_dataset('iris')
species = iris.pop("species")
g = sns.clustermap(iris)
g.fig.subplots_adjust(right=0.7)
g.ax_cbar.set_position((0.8, .2, .03, .4))

https://stackoverflow.com/questions/62882084
复制相似问题