def invert_ax(ax):
    """ Inverts x and y data on a plot axis, and flips limits.  Most useful for
    having an oriented axes in correlation side plots.
    """
    for line in ax.lines:
        xd = line.get_xdata()
        yd = line.get_ydata()
        line.set_xdata(yd)
        line.set_ydata(xd)

    xlim = ax.get_xlim()
    ylim = ax.get_ylim()
    ylim = (ylim[-1], ylim[0])
    ax.set_xlim(ylim)
    ax.set_ylim(xlim)
    return ax