I am using AxesGrid in matplotlib to create a plot that overlays two imshow plots, with a separate colourbar side by side for each image colourmap. While I can see in this question/answer that using pyplot.colorbar() automatically plots the second colour bar next to the first, this doesn't seem to work with AxesGrid.
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
fig = plt.figure(1, facecolor='white',figsize=(10,7.5))
grid = AxesGrid(fig, 111,
nrows_ncols=(1, 1),
axes_pad=(0.45, 0.15),
label_mode="1",
share_all=True,
cbar_location="right",
cbar_mode="each",
cbar_size="7%",
cbar_pad="2%",
)
im = grid[0].imshow(my_image, my_cmap)
cbar = grid.cbar_axes[0].colorbar(im)
im2 = grid[0].imshow(my_image_overlay, my_cmap2, alpha=0.5)
cbar2 = grid.cbar_axes[0].colorbar(im2)
plt.show()
However, this just shows the second colourbar. (Presumably overlaying the first one). I tried overriding the padding in cbar2 with:
cbar2 = grid.cbar_axes[0].colorbar(im2, pad=0.5)
but this results in an error with "got an unexpected keyword argument 'pad'"
Is there a way to offset the second colourbar?