Reputation: 1960
I'd like to change the text of the legend in a Seaborn boxplot
, but when I do the little rectangles/icons that show the hue in the legend become really thin, so I'd like to control the dimension of these icons as well:
Before changing labels (default legend):
After changing labels:
For reference, I'm changing labels using ax.legend(labels = [....])
Upvotes: 1
Views: 267
Reputation: 35145
Based on the official reference example, the code to get the handler of the legend and add an arbitrary label name.
import seaborn as sns
sns.set_theme(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips, palette="Set3")
handler, label = ax.get_legend_handles_labels()
ax.legend(handler, [1,0])
Upvotes: 1