As you can see on the image below, my entire plot (whether it's the heatmaps, the title or the colorbar) is “tighten” in the top of the figure/window and there is a large blank space in the bottom
Is there a way to lower it entirely AND to reduce the blank space in the bottom?
I've already tried to use the fig.tight_layout()
and to change the values of the figsize
argument of the plt.figure
function but the space in the bottom stays the same (proportionally)...
Here is the piece of code:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
def graphs():
fig = plt.figure(figsize=(13.5, 6.8))
Grid = AxesGrid(fig, 111, nrows_ncols=(1,3), axes_pad=0.2, share_all=False, label_mode='L', cbar_location="bottom", cbar_mode="single")
Matrices = [np.random.randint(-100,10,(10,10)) for i in range(3)]
M, m = np.max(Matrices), np.min(Matrices)
for values, ax in zip(Matrices, Grid):
ax.tick_params(top = True, bottom = False, labeltop = True, labelbottom = False)
ax.xaxis.set_label_position('top')
heatmap = ax.imshow(values, vmin=m, vmax=M, cmap='plasma')
ax.set_xticks(np.arange(0,10), labels=list(np.arange(1,11)), fontsize=6)
ax.set_xlabel('Arrival', fontweight='bold', fontsize=8)
plt.setp(ax.get_xticklabels(), rotation=35, ha="center", rotation_mode=None)
for l in range(len(values)):
for c in range(len(values[l])):
text = ax.text(c, l, values[l,c], ha="center", va="center", color='k', fontsize=6)
ax.set_title('Gaps', fontweight='bold', fontsize=9)
Grid[0].set_yticks(np.arange(0,10), labels=list(np.arange(1,11)), fontsize=6)
Grid[0].set_ylabel('Depart', fontweight='bold', fontsize=8)
for cax in Grid.cbar_axes:
cax.remove()
cbar = Grid[0].figure.colorbar(heatmap, ax = Grid, fraction=0.2, aspect=50, location='bottom', label='Gaps')
plt.suptitle('Visualisation of different gaps', fontsize=15, fontweight='bold', y=0.97)
plt.show()