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:
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With