简体   繁体   中英

How can I remove the Seaborn FacetGrid's legend title?

I am using Seaborn's FacetGrid to combine many plots in one figure and I want to remove the legend title. For instance, in the example below, I want to remove the title "sex".

import matplotlib.pyplot as plt
import seaborn as sns

tips = sns.load_dataset('tips')

g = sns.FacetGrid(tips, col= 'day')
g.map(sns.lineplot, 'total_bill', 'tip', 'sex', ci = False)    
g.add_legend()

在此处输入图片说明

I am aware of the discussion how to change the title in, eg, How can I change the Seaborn FacetGrid's legend title? However, I have not seen how to remove the legend title

I tried using the hack provided in this answer byImportanceOfBeingErnest and it works for your purpose

tips = sns.load_dataset('tips')
tips.columns = [n if n != "sex" else "" for n in tips.columns]

g = sns.FacetGrid(tips, col= 'day')
g.map(sns.lineplot, 'total_bill', 'tip', '', ci = False)    
leg = g.add_legend()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM