i using axesgrid in matplotlib create plot overlays 2 imshow plots, separate colourbar side side each image colourmap. while can see in this question/answer using pyplot.colorbar() automatically plots second colour bar next first, doesn't seem work axesgrid.
import matplotlib.pyplot plt 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, shows second colourbar. (presumably overlaying first one). tried overriding padding in cbar2 with:
cbar2 = grid.cbar_axes[0].colorbar(im2, pad=0.5)
but results in error "got unexpected keyword argument 'pad'"
is there way offset second colourbar?
i think may need make 2 axes colorbars , use them:
from mpl_toolkits.axes_grid1 import make_axes_locatable # create axes on right side of ax. width of cax 5% # of ax , padding between cax , ax fixed @ 0.05 inch. divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05)
'cause you're using same allocated space both.
Comments
Post a Comment