I am trying to reduce the white space on my matplotlib pcolormesh. This works well when I do not have the colorbar. But as soon as I add the colorbar to the plot, there is a large space on the right side of the colorbar. I made some minimal example, I am using Subplot from mpl_toolkits.axisartist, because in the real code I use the grid_helper argument to get non orthogonal axes.
import matplotlib.pyplot as plt
from mpl_toolkits.axisartist import Subplot
import numpy as np
Z = np.random.rand(6, 10)
x = np.arange(-0.5, 10, 1) # len = 11
y = np.arange(4.5, 11, 1) # len = 7
X, Y = np.meshgrid(x, y)
fig = plt.figure(figsize=(9, 3))
fig.patch.set_facecolor('red')
ax1 = Subplot(fig, 1, 1, 1)
ax = fig.add_subplot(ax1)
pm = ax.pcolormesh(X, Y, Z)
fig.colorbar(pm, pad=0.01)
fig.tight_layout(pad=0)
plt.show()
This results in:
I guess the problem is, that the colorbar is in its own subplot, but I have no clue how I can reduce the spacing in that subplot on the right side.
Any help is welcome.