【问题标题】:How can I remove the Seaborn FacetGrid's legend title?如何删除 Seaborn FacetGrid 的图例标题?
【发布时间】:2020-05-30 03:45:12
【问题描述】:

我正在使用 Seaborn 的 FacetGrid 将许多图组合在一个图中,我想删除图例标题。例如,在下面的示例中,我想删除标题“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()

我知道如何更改标题的讨论,例如,How can I change the Seaborn FacetGrid's legend title? 但是,我还没有看到如何删除图例标题

【问题讨论】:

    标签: python matplotlib seaborn


    【解决方案1】:

    我尝试使用ImportanceOfBeingErnest 提供的this 答案中提供的技巧,它适用于您的目的

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

    【讨论】:

    • 太好了,这行得通。似乎应该有一种非黑客的方式来做到这一点,但我想没有。
    猜你喜欢
    • 2022-01-28
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 2014-08-21
    • 2015-11-22
    • 1970-01-01
    相关资源
    最近更新 更多