ax = sns.scatterplot(x='X [um]', y='Y [um]', hue='label', size='size', data=data)
# extract the existing handles and labels
h, l = ax.get_legend_handles_labels()
# slice the appropriate section of l and h to include in the legend
ax.legend(h[0:13], l[0:13] ,bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show()
1条答案
按热度按时间lf5gs5x21#
我使用
get_legend_handles_labels()
功能来索引标签。使用索引,我确保最终打印的图像只包含图例中的前13个标签。