import numpy as np
import matplotlib.pyplot as plt


im = np.arange(100).reshape((10, 10))
ifu = np.arange(12).reshape((3, 4))

import matplotlib.gridspec as gridspec
from mpl_toolkits.axes_grid1 import ImageGrid



def draw1(fig, subplot_spec):
    subgrid = gridspec.GridSpecFromSubplotSpec(1, 2, subplot_spec, width_ratios=[1, 3])
        
    ax_im = fig.add_subplot(subgrid[0])
    ax_im.imshow(im, interpolation="none")

    #fig.add_subplot(subgrid[1])
    ifu_grid = ImageGrid(fig, subgrid[1], (1, 3), share_all=True,
                         cbar_mode="each", cbar_location="top")

    for ax in ifu_grid:
        im_ifu = ax.imshow(ifu, interpolation="none")
        ax.cax.colorbar(im_ifu)

# a single plot
fig1 = plt.figure(1)

gs1 = gridspec.GridSpec(1, 1,)
draw1(fig1, gs1[0])



# same plot in 10x3 grid
fig2 = plt.figure(2)

gs2 = gridspec.GridSpec(10, 3)

for subplot_spec in gs2:
    draw1(fig2, subplot_spec)
    

plt.show()
