def draw_residual(x, y, yerr, xerr,
                  show_errbars=True, ax=None,
                  zero_line=True, grid=True,
                  **kwargs):
    from matplotlib import pyplot as plt
    ax = plt.gca() if ax is None else ax
    if show_errbars:
        plotopts = dict(fmt='b.', capsize=0)
        plotopts.update(kwargs)
        pp = ax.errorbar(x, y, yerr, xerr, zorder=0, **plotopts)
    else:
        plotopts = dict(color='k')
        plotopts.update(kwargs)
        pp = ax.bar(x - xerr, y, width=2*xerr, **plotopts)
    if zero_line:
        ax.plot([x[0] - xerr[0], x[-1] + xerr[-1]], [0, 0], 'r-', zorder=2)
    if grid:
        ax.grid(grid)
    return ax