Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt
Last active December 3, 2019 14:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasaarholt/56d96909f6d823a98c10162c7c3522a9 to your computer and use it in GitHub Desktop.
Save thomasaarholt/56d96909f6d823a98c10162c7c3522a9 to your computer and use it in GitHub Desktop.
Add colorbar next to image
from mpl_toolkits.axes_grid1 import make_axes_locatable
def colorbar(mappable):
"mappable is img = plt.imshow()"
ax = mappable.axes
fig = ax.figure
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
cax.aname = 'colorbar'
return fig.colorbar(mappable, cax=cax)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment