Last active
March 22, 2023 14:20
-
-
Save blaylockbk/e315c5e5aededb6aee6b08d1316f3d62 to your computer and use it in GitHub Desktop.
Adding colorbar on axes
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 | |
from mpl_toolkits.axes_grid1 import make_axes_locatable | |
data1 = np.random.random([5,5]) | |
data2 = np.random.random([5,5]) | |
fig = plt.figure(1, figsize=[16, 4]) | |
ax1 = fig.add_subplot(121) | |
ax2 = fig.add_subplot(122) | |
this_plot = ax1.pcolormesh(data1, cmap='magma') | |
this_plot = ax2.pcolormesh(data2, cmap='magma') | |
divider = make_axes_locatable(ax2) | |
#cax = divider.append_axes('bottom', size='6%', pad=.25) # Method 1 | |
cax = fig.add_axes([0.3, -0.0, 0.4, 0.05]) # Method 2, where the list is a rectangle [left, bottom, width, height] | |
cb = fig.colorbar(this_plot, cax=cax, orientation='horizontal') | |
cb.set_label('label and (units)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Produces this figure: