You are reading an old version of the documentation (v1.4.3). For the latest version see

We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates


Previous topic

axes_grid example code:

Next topic

axes_grid example code:

This Page

axes_grid example code: demo_colorbar_with_inset_locator.pyΒΆ

(Source code, png, hires.png, pdf)

import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1.inset_locator import inset_axes

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[6, 3])

axins1 = inset_axes(ax1,
                    width="50%", # width = 10% of parent_bbox width
                    height="5%", # height : 50%

im1=ax1.imshow([[1,2],[2, 3]])
plt.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1,2,3])

axins = inset_axes(ax2,
                   width="5%", # width = 10% of parent_bbox width
                   height="50%", # height : 50%
                   bbox_to_anchor=(1.05, 0., 1, 1),

# Controlling the placement of the inset axes is basically same as that
# of the legend.  you may want to play with the borderpad value and
# the bbox_to_anchor coordinate.

im=ax2.imshow([[1,2],[2, 3]])
plt.colorbar(im, cax=axins, ticks=[1,2,3])


Keywords: python, matplotlib, pylab, example, codex (see Search examples)