Home > Mobile >  How to add labels to sets of seaborn boxplot
How to add labels to sets of seaborn boxplot

Time:02-25

I have 2 sets of boxplots, one set in blue color and another in red color. I want the legend to show the label for each set of boxplots, i.e.

Legend: -blue box- A, -red box- B

Added labels='A' and labels='B' within sns.boxplot(), but didn't work with error message "No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument". How do I add the labels?

sns.boxplot legend labels from artists

Alternative approaches could be:

  • pd.melt the dataframe to long form, so hue could be used; a problem here is that then the legend wouldn't take the alpha from the boxprops into account; also setting different fliers wouldn't be supported
  • create a legend from custom handles
  • Related