def add_cbar(im, ax): divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="10%", pad=0.05) plt.colorbar(im, cax=cax)