简体   繁体   English

如何删除 Seaborn FacetGrid 的图例标题?

[英]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.我正在使用 Seaborn 的 FacetGrid 将许多图组合在一个图中,我想删除图例标题。 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?我知道关于如何更改标题的讨论,例如, 如何更改 Seaborn FacetGrid 的图例标题? 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我尝试使用ImportanceOfBeingErnest这个答案中提供的技巧,它适用于您的目的

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()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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