Home > Enterprise >  how can I add legend in seaborn (countplot)
how can I add legend in seaborn (countplot)

Time:03-07

sns.countplot with legend

Note that when you aren't using hue, no legend is added as the names and colors are given by the x tick labels.

CodePudding user response:

You can add a legend manually by passing a list of the desired labels like this:

plt.legend(labels = ['type 1', 'type 2'])

here is a nice blog post on the topic: https://www.delftstack.com/howto/seaborn/legend-seaborn-plot/

  • Related