Python 如何为 Seaborn Facet Plot 添加标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29813694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add a title to Seaborn Facet Plot
提问by I am not George
How do I add a title to this Seaborne plot? Let's give it a title 'I AM A TITLE'.
我如何为这个 Seaborne 情节添加标题?让我们给它一个标题“我是一个头衔”。
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="sex", row="smoker", margin_titles=True)
g.map(sns.plt.scatter, "total_bill", "tip")
采纳答案by cphlewis
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.
如果在不调整轴的情况下添加 suptitle,seaborn facet 标题会与其重叠。
(With different data):
(使用不同的数据):
回答by Meera Lakhavani
In ipython notebook, this worked for me!
在 ipython notebook 中,这对我有用!
sns.plt.title('YOUR TITLE HERE')
回答by pmetzner
What worked for me was:
对我有用的是:
sns.plt.suptitle('YOUR TITLE HERE')
sns.plt.suptitle('YOUR TITLE HERE')
回答by Taras
g.fig.subplots_adjust(top=0.9)
g.fig.suptitle('Title', fontsize=16)
More info here: http://matplotlib.org/api/figure_api.html
回答by crypdick
The answers using sns.plt.title()
and sns.plt.suptitle()
don't work anymore.
使用sns.plt.title()
和sns.plt.suptitle()
不再起作用的答案。
Instead, you need to use matplotlib's title()
function:
相反,您需要使用 matplotlib 的title()
函数:
import matplotlib.pyplot as plt
sns.FacetGrid(<whatever>)
plt.title("A title")
回答by Vraj Patel
plt.suptitle("Title")
or
或者
plt.title("Title")
This worked for me.
这对我有用。