3
$\begingroup$

I'm trying to plot three heatmaps in a vertical column using Seaborns subplot method.

import seaborn as sns
initalCorr = inputX.corr()
secondaryCorr = inputX_corr.corr()
finalCorr = inputX[selected_columns_pvalue].corr()

fig, axs = plt.subplots(3, figsize = (15,45))
fig.suptitle('Heatmaps of correlation between features selected for training',
fontsize = 20)

sns.heatmap(data = initalCorr, center = 0, square = True, ax = axs[0])
axs[0].set_title('Correlation between all features', fontsize = 20)   

sns.heatmap(secondaryCorr, center = 0, square = True, annot = True, linewidths = .5, fmt = '.2f', ax = axs[1])
axs[1].set_title('Correlation between features slected for P-Value analysis', fontsize = 20)

sns.heatmap(finalCorr, center = 0, square = True, annot = True, linewidths = .5, fmt = '.2f', ax = axs[2])
axs[2].set_title('Correlation between finally selected features', fontsize = 20) 

The graphs themselves plot fine but the title appears out of place relative to the plots.

Image showing the out of place title text

How do I make the title directly above the heatmaps?

Additional: seaborn version 0.9.0 matplotlib version 3.0.3

$\endgroup$
2
$\begingroup$

You can move the title closer to the first figure. Just add the following two lines at the end of the code

fig.tight_layout()
fig.subplots_adjust(top=0.95)

ReduceWhiteSpace

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.