-1

For a plot as below.

enter image description here

There is an issue whereby the Main title is on the same line with the other sub-title.

May I know how shift the suptitle further up?

The code to reproduce the above figure is as below

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()
mpx
  • 3,081
  • 2
  • 26
  • 56

1 Answers1

0

.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" )

enter image description here

Jay Patel
  • 1,374
  • 1
  • 8
  • 17