【问题标题】:Elegant way to change legend's title size in seaborn plot?在 seaborn 情节中改变传说标题大小的优雅方式?
【发布时间】:2018-07-20 13:47:29
【问题描述】:

我创建了一个 seaborn 配对图,我想更改图例标题的大小。 我已经做到了:

matrix = sns.pairplot(...)
lg = plt.gcf().legend(title='something')
lg.get_title().set_fontsize(30)

有没有更优雅的方法来做到这一点?

我知道 seaborn 使用的 matplotlib 没有此处讨论的相关属性:https://github.com/matplotlib/matplotlib/issues/8699

【问题讨论】:

    标签: python matplotlib seaborn


    【解决方案1】:

    注意from matplotlib 3.0 on,你可以通过改变图例标题字体大小

    ax.legend(..., title_fontsize=16)
    

    plt.rcParams['title_fontsize'] = 16
    

    到那时,

    legend = ax.legend(...)
    legend.get_title().set_fontsize(16)
    

    确实是设置图例标题的合适方式。

    【讨论】:

    • 好吧,至少很高兴知道仍然没有更好的方法来做到这一点
    【解决方案2】:

    更改图例的标题字体大小

    plt.title('something', fontsize=16)

    【讨论】:

    • 这不会改变图例的标题字体大小,不知道为什么会被接受?
    猜你喜欢
    • 1970-01-01
    • 2019-08-28
    • 2023-03-10
    • 2020-02-14
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 2016-10-11
    相关资源
    最近更新 更多