I am trying to make a figure with six individual plots, organized in two rows of three plots. Each row of plots should have its own color bar corresponding to the images shown in the three plots in a horizontal group. Laid out visually, the figure should look like:
image_type1 | image_type1 | image_type1 | colorbar_for_type1_images
image_type2 | image_type2 | image_type2 | colorbar_for_type2_images
The vertical lines in the representation above are just to separate the different components of the figure. I don't actually need vertical lines in my figure.
An example of what I'm trying to do is shown below, as well as my unsuccessful attempts to get a color bar to be plotted with the third image in each row.
I've been able to do this successfully in the past with code similar to what appears below when I was using my own color map for a series of plotted lines, rather than for images as I'm trying to do below.
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.cbook import get_sample_data
#Make 6 plotting areas of the same dimensions
figuresizex = 9.0
figuresizey = 6.1
lowerx = .07
lowery = .09
upperx = .92
uppery = .97
xspace = .05
yspace = .11
xwidth = (upperx-lowerx-2*xspace)/3.
ywidth = (uppery-lowery-yspace)/2.
fig = plt.figure(figsize=(figuresizex,figuresizey))
ax1 = fig.add_axes([lowerx,lowery+ywidth+yspace,xwidth,ywidth])
ax2 = fig.add_axes([lowerx+xwidth+xspace,lowery+ywidth+yspace,xwidth,ywidth])
ax3 = fig.add_axes([lowerx+2*xwidth+2*xspace,lowery+ywidth+yspace,xwidth,ywidth])
ax4 = fig.add_axes([lowerx,lowery,xwidth,ywidth])
ax5 = fig.add_axes([lowerx+xwidth+xspace,lowery,xwidth,ywidth])
ax6 = fig.add_axes([lowerx+2*xwidth+2*xspace,lowery,xwidth,ywidth])
axlist = [ax1,ax2,ax3,ax4,ax5,ax6]
#Start plotting images
image = np.identity(5)
for i in range(0,3):
vmin, vmax = image.min(),image.max()
axuse = axlist[i]
im = axuse.imshow(image, vmin=vmin, vmax=vmax)
if i == 3:
cbar = axuse.colorbar(im)
cbar = plt.colorbar(im)
image_2 = np.arange(16).reshape((4,4))
for i in range(0,3):
vmin, vmax = image_2.min(),image_2.max()
axuse = axlist[i+3]
axuse.imshow(image_2,vmin=vmin, vmax=vmax)
if i == 3:
cbar = axuse.colorbar()
cbar = plt.colorbar()
plt.show()