首页 文章

如何注释seaborn pairplots?

提问于
浏览
7

我有一个binned数据集合,我从中生成了一系列seaborn pairplots . 由于所有的bin都有相同的标签,但没有bin名称,我需要在下面用bin名称'n'注释pairplots,以便稍后我可以将它们与bin结合起来 .

import seaborn as sns
groups = data.groupby(pd.cut(data['Lat'], bins))
for n,g in groups:
    p = sns.pairplot(data=g, hue="Label", palette="Set2", 
                 diag_kind="kde", size=4, vars=labels)

我在文档中注意到seaborn使用或构建在matplotlib上 . 我一直无法弄清楚如何在左侧标注图例,或在配对图的上方或下方提供 Headers . 任何人都可以提供有关如何将任意文本添加到绘图的这三个区域的文档的指针示例吗?

1 回答

  • 11

    在跟进mwaskom建议使用matplotlib.text()(谢谢)之后,我能够按预期方式使用以下内容:

    p = sns.pairplot(data=g, hue="Label", palette="Set2", 
                 diag_kind="kde", size=4, vars=labels)
    #bottom labels
    p.fig.text(0.33, -0.01, "Bin: %s"%(n), ha ='left', fontsize = 15)
    p.fig.text(0.33, -0.04, "Num Points: %d"%(len(g)), ha ='left', fontsize = 15)
    

    和其他有用的功能:

    # title on top center of subplot
    p.fig.suptitle('this is the figure title', verticalalignment='top', fontsize=20)
    
    # title above plot
    p.fig.text(0.33, 1.02,'Above the plot', fontsize=20)
    
    # left and right of plot
    p.fig.text(0, 1,'Left the plot', fontsize=20, rotation=90)
    p.fig.text(1.02, 1,'Right the plot', fontsize=20, rotation=270)
    
    # an example of a multi-line footnote
    p.fig.text(0.1, -0.08,
         'Some multiline\n'
         'footnote...',
          fontsize=10)
    

相关问题