I am trying to plot 6 plots in the form of a grid using gridspec. I want one color bar placed at the bottom between the 2nd and 3rd columns.
My code is as follows, but it generates 6 colorbars. How can I change this code so that it places one colorbar at the bottom between the two columns?
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
plt.figure(figsize=(8, 6))
gs = gridspec.GridSpec(2, 3)
gs.update(wspace= 1)
cmaps = ['RdBu_r', 'viridis', 'viridis']
for i in range(2):
for j in range(3):
ax = plt.subplot(gs[i, j])
image = ax.pcolormesh(np.random.random((20, 20)) * (j + 1),
cmap=cmaps[j])
#image = ax.imshow(im)
axins = inset_axes(ax,
width="10%",
height="100%",
loc='lower left',
bbox_to_anchor=(1.05, 0.0, 1, 1),
bbox_transform=ax.transAxes,
borderpad=0
)
cb = plt.colorbar(image, cax=axins)
I want the color bar placed horizontally at the bottom spanning columns 2 and 3 (I marked in red where I want it to be placed).