如何在Seaborn绘图中转移字幕 [英] How to shift suptitle in Seaborn displot
本文介绍了如何在Seaborn绘图中转移字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用于以下情节.
存在一个问题,即主要标题
与其他子标题在同一行.
There is an issue whereby the Main title
is on the same line with the other sub-title.
我可以知道 suptitle
进一步上移吗?
May I know how shift the suptitle
further up?
复制上图的代码如下
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset("iris")
fig=plt.figure()
g = sns.displot ( data=iris, x='petal_width', col='species', col_wrap=2, bw_adjust=0.5,
kind="kde", rug=True)
header_name =['1a','1b','1c','1d']
value_tick = [0.5,1,1.5,3]
g.set_xticklabels (rotation=45 )
plt.suptitle('Main title')
plt.xticks ( ticks=value_tick, labels=header_name, ha="right" )
plt.show()
推荐答案
.suptitle(...)
is a matplotlib figure function. It has x
and y
arguments, with y=0.98
as the default. You can adjust it to be a bit higher, instead of moving the subplots (in some cases you may not have enough freedom there).
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset("iris")
fig=plt.figure()
#plt.suptitle("Main Title")
g = sns.displot ( data=iris, x='petal_width', col='species', col_wrap=2, bw_adjust=0.5, kind="kde", rug=True)
header_name =['1a','1b','1c','1d']
value_tick = [0.5,1,1.5,3]
g.set_xticklabels (rotation=45 )
g.fig.suptitle("My super title", y=1.05)
#plt.suptitle('Main title')
plt.xticks ( ticks=value_tick, labels=header_name, ha="right" )
这篇关于如何在Seaborn绘图中转移字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文