-
-
Save snsinfu/ebc8c1d78f95fa215bc72f3e7d135d8c to your computer and use it in GitHub Desktop.
Short colorbar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import mpl_toolkits.axes_grid1.inset_locator | |
fig, ax = plt.subplots() | |
matrix = np.random.normal(size=(100, 100)) | |
sm = ax.matshow(matrix) | |
# Attach a small axes to the lower right of the main axes. It's an "inset" | |
# placed outside of the plot. The size is 0.02 width x 0.5 height of the | |
# main axes. | |
cbar_ax = mpl_toolkits.axes_grid1.inset_locator.inset_axes( | |
ax, | |
width="100%", height="100%", | |
bbox_to_anchor=(1.02, 0, 0.02, 0.5), bbox_transform=ax.transAxes, | |
borderpad=0 | |
) | |
cbar = fig.colorbar(sm, cax=cbar_ax) | |
# If you favor an unbordered colorbar. | |
cbar.outline.set_edgecolor("none") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment