I've plotted a graph containing many subplots, by using matplotlib in Python 3. I inserted the figure title by using fig.text()
rather than fig.suptitle()
because I need to place the title in the middle, on the right, and on the left. You can see this result in the next url (number of rows = 6):
Now, I have some problems when the number of subplots increase or decrease. The space between the title and the top of the upper subplots decrease or increase. The x label has the same behavior as well.
For instance, when number of rows = 2 that space decrease, as you can see in the next picture:
In the other hand, when number of rows = 15 that space increase, as you can see in the next picture:
I want that the space of the title and the x axis label don't change when I increase or decrease the number of rows. Any suggestion? Thank you.
This is my MWE:
import matplotlib.pyplot as plt
n_rows = 15
n_cols = 2
fig, axs = plt.subplots(n_rows, n_cols, figsize=(7*n_cols,1*n_rows), sharex="col", sharey="row",
gridspec_kw={'hspace': 0, 'wspace': 0})
# labels
fig.text(0.513, 0.06, 'Time UTC', ha='center', va='center', fontsize=14)
fig.text(0.09, 0.5, 'S4', ha='center', va='center', rotation='vertical', fontsize=14, color='b')
fig.text(0.94, 0.5, 'Elevation Angle', ha='center', va='center', rotation=-90, fontsize=14, color='g')
# title
fig.text(0.513, 0.91, 'S4', ha='center', va='center', fontsize=17)
fig.text(0.32, 0.91, 'Jicamarca', ha='center', va='center', fontsize=17, color='r')
fig.text(0.12, 0.91, '2020/07/16', ha='left', va='center', fontsize=17)
fig.text(0.9, 0.91, 'Scintillation index', ha='right', va='center', fontsize=17)