@bogatron already gave the answer suggested by matplotlib docs , which creates the correct height, but presents another problem. Now the width of the color panel (as well as the space between color and plot) changes with the width of the graph. In other words, the aspect ratio of the color bar is no longer fixed.
To get both the correct height and the specified aspect ratio, you need to delve into the mysterious module axes_grid1 .
import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size import numpy as np aspect = 20 pad_fraction = 0.5 ax = plt.gca() im = ax.imshow(np.arange(200).reshape((20, 10))) divider = make_axes_locatable(ax) width = axes_size.AxesY(ax, aspect=1./aspect) pad = axes_size.Fraction(pad_fraction, width) cax = divider.append_axes("right", size=width, pad=pad) plt.colorbar(im, cax=cax)
Please note that this indicates the width of the color panel wrt the height of the graph (as opposed to the width of the shape, as it was before).
The interval between the color panel and graphics can now be set as part of the width of the color panel, which is IMHO a much more significant number than the proportion of the width of the figure.

UPDATE:
I created an IPython laptop on a topic where I packed the above code into an easily reusable function:
import matplotlib.pyplot as plt from mpl_toolkits import axes_grid1 def add_colorbar(im, aspect=20, pad_fraction=0.5, **kwargs): """Add a vertical color bar to an image plot.""" divider = axes_grid1.make_axes_locatable(im.axes) width = axes_grid1.axes_size.AxesY(im.axes, aspect=1./aspect) pad = axes_grid1.axes_size.Fraction(pad_fraction, width) current_ax = plt.gca() cax = divider.append_axes("right", size=width, pad=pad) plt.sca(current_ax) return im.axes.figure.colorbar(im, cax=cax, **kwargs)
It can be used as follows:
im = plt.imshow(np.arange(200).reshape((20, 10))) add_colorbar(im)