def plotter(z, x, y, pixelaspect, **kwargs):
    xinches = len(x)/float(dpi)
    yinches = len(y)/float(dpi)*pixelaspect
    figsize = (xinches + 1.5, yinches + 1)
    fig = plt.figure(figsize=figsize)
    ax = plt.subplot(111)
    el.make_axes_fixed(ax, xinches, yinches)
    img = el.implot(z, x, y, ax=ax, csize=0.0625, cpad=0.05, **kwargs)
    plt.tight_layout(0.01)
    return fig
def plot_recovery(x):
    img = el.implot(np.abs(np.fft.fftshift(x, axes=0)), 
                    np.fft.fftshift(velocity_idx/1e3), 
                    range_idx/1e3,
                    xlabel='Range rate (km/s)',
                    ylabel='Range (km)',
                    clabel='Reflectivity',
                    exact_ticks=False,
                    xbins=4, ybins=5,
                    vmin=0, vmax=20,
                    csize=0.0625, cpad=0.05)
    img.axes.set_xlim(-15, 60)
    img.axes.set_ylim(98, 102)
    plt.tight_layout(0.1)
    return img
          'text.usetex': False}
          #'text.latex.preamble': ['\usepackage{amsmath}']}
plt.rcParams.update(params)

delta = 0.1
x = y = np.arange(0, 100, delta)
X, Y = np.meshgrid(x,y)
Z1 = mlab.bivariate_normal(X, Y, 5, 10, 25, 30)
Z1 = Z1/np.max(Z1)
Z2 = mlab.bivariate_normal(X, Y, 1, 1, 71, 61)
Z2 = Z2/np.max(Z2)

f = x/100. - 0.5
d = y

fig = plt.figure(figsize=(2,2))
img = el.implot(10*(Z1 + 2*Z2).T, f, d, 
                csize=0.0625, cpad=0.05, 
                exact_ticks=False, xbins=6, ybins=6, 
                interpolation='bilinear',
                xlabel='Normalized Frequency', ylabel='Delay (samples)', 
                clabel='Reflectivity')
ax = img.axes
ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.02))
ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(2.0))
ax.grid(which='minor', color='m', linewidth=0.45, linestyle='-')

#plt.show()
fig.savefig('range_doppler_discretization.pdf', bbox_inches='tight', 
            pad_inches=0.01, transparent=True)
    cs_sig = cs.vlt_sig[pslc]
    cs_noise = cs.vlt_noise[pslc]
    
    filt = filts[kp]

    zs = np.zeros((n, m), np.float_)
    
    xinches = len(v)/float(imgdpi)*xstretch
    yinches = len(data.r)/float(imgdpi)*ystretch
    fig, axes = plt.subplots(1, 2, sharey=True, figsize=(2*xinches + 1, yinches + 0.55))
    el.make_axes_fixed(axes[0], xinches, yinches)
    el.make_axes_fixed(axes[1], xinches, yinches)
    mfimg = el.implot(zs, 
                      np.fft.fftshift(v)/1e3, data.r/1e3,
                      xlabel='Doppler range rate (km/s)', ylabel='Range (km)',
                      cbar=False, title='Matched Filter', 
                      exact_ticks=False, xbins=5,
                      vmin=0, vmax=40, 
                      cmap=cmap, csize=0.0625, cpad=0.05,
                      pixelaspect=pixelaspect, ax=axes[0])
    csimg = el.implot(zs, 
                      np.fft.fftshift(cs.v)/1e3, cs.r/1e3,
                      xlabel='Doppler range rate (km/s)',
                      clabel='SNR (dB)', title='Waveform Inversion',
                      exact_ticks=False, xbins=5,
                      vmin=0, vmax=40, 
                      cmap=cmap, csize=0.0625, cpad=0.05,
                      pixelaspect=pixelaspect, ax=axes[1])
    plt.tight_layout(0.1)
    plt.draw() # need draw to update axes position
    # need the resolution to be multiples of 2 for libx264
    savesize = np.floor(savedpi*fig.get_size_inches())