Ben*_*abl 7 python matplotlib legend seaborn
我正在使用seaborn散点图,并且刚刚开始使用不同的点大小。
sns.scatterplot(x='X [um]', y='Y [um]', hue='label', size='size', data=data)
Run Code Online (Sandbox Code Playgroud)
带有 CH1 等的上部部分应保持不变,但我希望列出尺寸的下部部分消失。
我使用该get_legend_handles_labels()功能来索引标签。使用索引,我确保最终打印的图像仅包含图例中的前 13 个标签。
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3888 次 |
| 最近记录: |