user5826447
user5826447

Reputation: 367

Changing pointplot legend in seaborn

I would like to change the label for the legend and items in the legend for this plot. Right now the label for the legend is "Heart" and the items are 0 and 1. I would like to be able to change all of these to something else, but am unsure how. Here is what I have so far.

sns.set_context("talk",font_scale=3)
ax =sns.pointplot(x="Heart", y="FirstPersonPronouns", hue="Speech", data=df)
ax.set(xlabel='Condition', ylabel='First Person Pronouns')
ax.set(xticklabels=["Control", "Heart"])

Any help would be appreciated! Also, I'm assuming this is a set parameter that I don't know about, is there a comprehensive list of these? I can't seem to find one in the documentation.

Upvotes: 4

Views: 5182

Answers (1)

joelostblom
joelostblom

Reputation: 49064

An alternative to changing the column names of the data frame, is to create a new legend using the same legend handles (this is what determines the colored markers), but with new text labels:

import seaborn as sns

tips = sns.load_dataset('tips')
ax = sns.pointplot(x='sex', y='total_bill', hue='time', data=tips)
leg_handles = ax.get_legend_handles_labels()[0]
ax.legend(leg_handles, ['Blue', 'Orange'], title='New legend')

enter image description here

Upvotes: 3

Related Questions