def axis_transform(ax, x, y, xlim=None, ylim=None, inverse=False):
xlim = xlim or ax.get_xlim()<EOL>ylim = ylim or ax.get_ylim()<EOL>xdelta = xlim[<NUM_LIT:1>] - xlim[<NUM_LIT:0>]<EOL>ydelta = ylim[<NUM_LIT:1>] - ylim[<NUM_LIT:0>]<EOL>if not inverse:<EOL><INDENT>xout = xlim[<NUM_LIT:0>] + x * xdelta<EOL>yout = ylim[<NUM_LIT:0>] + y * ydelta<EOL><DEDENT>else:<EOL><INDENT>xdelta2 = x - xlim[<NUM_LIT:0>]<EOL>ydelta2 = y - ylim[<NUM_LIT:0>]<EOL>xout = xdelta2 / xdelta<EOL>yout = ydelta2 / ydelta<EOL><DEDENT>return xout, yout<EOL>
http://stackoverflow.com/questions/29107800

inverse = False : Axis => Data
        = True  : Data => Axis