How to remove specific part of legend (seaborn, scatterplot)

Viewed 1677

I am using a seaborn scatterplot and just started using different point sizes.

sns.scatterplot(x='X [um]', y='Y [um]', hue='label', size='size', data=data)

All works perfectly but I'd like to remove the 'size' from the legend seen in picture: enter image description here

The upper part with CH1, etc. shall remain the same but I'd want the lower part where the sizes are listed to vanish.

1 Answers

I use the get_legend_handles_labels() functionality to index the labels. Using indexing, I ensure that the final printed image only contains the first 13 labels in your legend.

 g = sns.scatterplot(x='X [um]', y='Y [um]', hue='label', size='size', data=data)
    h,l = g.get_legend_handles_labels()
    plt.legend(h[0:13],l[0:13],bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
    plt.show(g)
Related