I have the following code that plots 3 heatmaps in a row and then adds a shared colorbar to the right of the heatmaps:
import numpy as np
import matplotlib.pyplot as plt
num_rows = 100
num_cols = 200
noise_array_1 = np.random.rand(num_rows, num_cols)
noise_array_2 = np.random.rand(num_rows, num_cols)
noise_array_3 = np.random.rand(num_rows, num_cols)
figure, axes = plt.subplots(1, 3)
figure.set_dpi(200)
figure.suptitle("Heat maps title")
heatmap = axes[0].imshow(noise_array_1, cmap="jet")
heatmap = axes[1].imshow(noise_array_2, cmap="jet")
heatmap = axes[2].imshow(noise_array_3, cmap="jet")
figure.subplots_adjust(right=0.8)
colorbar_axes = figure.add_axes([0.85, 0.1, 0.01, 0.3])
figure.colorbar(heatmap, cax=colorbar_axes)
plt.show()
However, there is a huge amount of white space above and below the plots. I've tried a few methods to solve this issue, but they usually end up removing the white space at the cost of messing up the position of the shared colorbar. As such, what I'm trying to do is the following:
- Remove white space above and below the subplots
- Position the colorbar correctly once the white space has been removed
This is the output I currently get:

