code: def plot1D_mat(a, b, M, title=''):
      
      na, nb = M.shape
  
      gs = gridspec.GridSpec(3, 3)
  
      xa = np.arange(na)
      xb = np.arange(nb)
  
      ax1 = pl.subplot(gs[0, 1:])
      pl.plot(xb, b, 'r', label='Target distribution')
      pl.yticks(())
      pl.title(title)
  
      ax2 = pl.subplot(gs[1:, 0])
      pl.plot(a, xa, 'b', label='Source distribution')
      pl.gca().invert_xaxis()
      pl.gca().invert_yaxis()
      pl.xticks(())
  
      pl.subplot(gs[1:, 1:], sharex=ax1, sharey=ax2)
      pl.imshow(M, interpolation='nearest')
      pl.axis('off')
  
      pl.xlim((0, nb))
      pl.tight_layout()
      pl.subplots_adjust(wspace=0., hspace=0.2)
docs: Plot matrix M  with the source and target 1D distribution
  
      Creates a subplot with the source distribution a on the left and
      target distribution b on the tot. The matrix M is shown in between.
  
  
      Parameters
      ----------
      a : np.array, shape (na,)
          Source distribution
      b : np.array, shape (nb,)
          Target distribution
      M : np.array, shape (na,nb)
          Matrix to plot