Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding text to each subplot in seaborn

Tags:

I am making bar graphs in seaborn and I want to add some text to each subplot. I know how to add text to the entire figure, but I want to access each subplot and add text. I am using this code:

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

which gives me this: enter image description here

like image 579
Stefano Potter Avatar asked Jan 06 '17 17:01

Stefano Potter


People also ask

How do I add a title to Seaborn subplot?

To add a title to a single seaborn plot, you can use the . set() function. To add an overall title to a seaborn facet plot, you can use the . suptitle() function.

How do you make multiple subplots in Seaborn?

You can use the following basic syntax to create subplots in the seaborn data visualization library in Python: #define dimensions of subplots (rows, columns) fig, axes = plt. subplots(2, 2) #create chart in each subplot sns. boxplot(data=df, x='team', y='points', ax=axes[0,0]) sns.


1 Answers

During your for loop you already have each subplot available to you with 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
like image 97
Ted Petrou Avatar answered Sep 21 '22 17:09

Ted Petrou