24

The seaborn stripplot has a function which allows hue.

Using the example from https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.stripplot.html

import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.stripplot(x=tips["total_bill"])
ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)

enter image description here

In this case, the legend is quite small, showing a different hue for each day. However, I would like to remove the legend.

Normally, one includes a parameter legend=False. However, for stripplot, this appears to output an attribute error:

AttributeError: Unknown property legend

Can one remove the legend for stripplots? If so, how does one do this?

Serenity
  • 35,289
  • 20
  • 120
  • 115
ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234

1 Answers1

54

Use ax.legend_.remove() like here:

import seaborn as sns
import matplotlib.pylab as plt
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)

# remove legend from axis 'ax'
ax.legend_.remove()

plt.show()

enter image description here

Serenity
  • 35,289
  • 20
  • 120
  • 115