1
votes

I am trying to add main title to plot and also minor titles to every single subplot. I cannot figure out how to do it properly. It happens that main title is located in the same place as a title of a subplot. How to move all subplots under main title? This is how I tried to do it:

fig = plt.figure(figsize=(8.0, 5.0))
fig.suptitle('MAIN TITLE', horizontalalignment='left', fontsize=10)
plt.subplot(2, 1, 1)
plt.gca().set_title('SUBPLOT TITLE', fontsize=10)
1
Whe I run your code, it looks like this. It looks ok to me. Can you explain exactly what is wrong with that? - ImportanceOfBeingErnest

1 Answers

0
votes

You can always add plt.tight_layout() at the end of a figure creation. It tries to arrange everything so that all features get their space.
And if you are still not convinced, you can control the space of the subplots with the rect kwarg, e.g.:

plt.tight_layout(rect=[0, 0, 1,. 95])

https://matplotlib.org/api/tight_layout_api.html