How to add a title to Seaborn Facet Plot

2019-01-30 18:07发布

问题:

How do I add a title to this Seaborne plot? Let's give it a title 'I AM A TITLE'.

tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="sex", row="smoker", margin_titles=True)
g.map(sns.plt.scatter, "total_bill", "tip")

回答1:

After those lines:

plt.subplots_adjust(top=0.9)
g.fig.suptitle('THIS IS A TITLE, YOU BET') # can also get the figure from plt.gcf()

If you add a suptitle without adjusting the axis, the seaborn facet titles overlap it.

(With different data):



回答2:

In ipython notebook, this worked for me!

sns.plt.title('YOUR TITLE HERE')


回答3:

g.fig.subplots_adjust(top=0.9)
g.fig.suptitle('Title', fontsize=16)

More info here: http://matplotlib.org/api/figure_api.html



回答4:

What worked for me was:

sns.plt.suptitle('YOUR TITLE HERE')



回答5:

The answers using sns.plt.title() and sns.plt.suptitle() don't work anymore.

Instead, you need to use matplotlib's title() function:

import matplotlib.pyplot as plt
sns.FacetGrid(<whatever>)
plt.title("A title")