在seaborn中为每个子图添加文本

Ste*_*ter 10 python seaborn

我在seaborn制作条形图,我想在每个子图中添加一些文字.我知道如何向整个图形添加文本,但我想访问每个子图并添加文本.我正在使用此代码:

import seaborn as sns
import pandas as pd

sns.set_style("whitegrid")

col_order=['Deltaic Plains','Hummock and Swale', 'Sand Dunes']

g = sns.FacetGrid(final, col="Landform", col_wrap=3,despine=False, sharex=False,col_order=col_order)

    g = g.map(sns.barplot, 'Feature', 'Importance')

    [plt.setp(ax.get_xticklabels(), rotation=45) for ax in g.axes.flat]

    for ax, title in zip(g.axes.flat, col_order):
        ax.set_title(title)

    g.fig.text(0.85, 0.85,'Text Here', fontsize=9) #add text
Run Code Online (Sandbox Code Playgroud)

这给了我这个: 在此输入图像描述

Ted*_*rou 14

在for循环期间,您已经拥有了每个子图ax.

for ax, title in zip(g.axes.flat, col_order):
    ax.set_title(title)
    ax.text(0.85, 0.85,'Text Here', fontsize=9) #add text
Run Code Online (Sandbox Code Playgroud)