Remove seaborn lineplot legend title

Daniel picture Daniel · Jul 29, 2018 · Viewed 21.3k times · Source

I would like to remove the title from my seaborn lineplot legend. I tried using this answer to no avail:

import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
fmri = sns.load_dataset("fmri")
fig, ax = plt.subplots()
g = sns.lineplot(x="timepoint", y="signal", hue="event", data=fmri, ax=ax)
ax.legend().set_title('')

Seaborn lineplot still with 'event' title

I get the same if I try to set the title to None. Interestingly, setting the title to something else seems to prepend to the existing title:

ax.legend().set_title('Something else')

Seaborn lineplot still with prepend title

It almost looks like seaborn is treating the title as a hidden legend entry. How can I resolve this?

Answer

ImportanceOfBeingErnest picture ImportanceOfBeingErnest · Jul 29, 2018

Important: This answer is about the case when a hue is used that appears as a legend title. In all other cases, the question itself already contains the usual way to get rid of a title.