import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
fig = plt.figure()
ax = plt.gca()
im = ax.imshow(np.arange(100).reshape((10, 10)), aspect=0.5)
divider = make_axes_locatable(ax)
cax = divider.append_axes('right', size='5%', pad=0.05, aspect=10)
plt.colorbar(im, cax=cax)
plt.show()
matplotlib imshow fixed aspect and vertical colorbar matching master axis height