When using pgfplots, the command \pgfgetlastxy works well without axis environment and with axis environment set as default.
But it is hard getting the correct coordinate of intersecting, when setting something with the axis environment.

I want to get the result with the MWE below.
\documentclass{standalone}
%\usepackage{amsthm,amssymb}
\usepackage{pgfplots}
\usetikzlibrary{arrows,intersections,calc}
\begin{document}
\begin{tikzpicture}[font=\footnotesize]
\begin{axis}[%
axis lines*=none,axis y line=center, axis x line=center,
xlabel=$x$,ylabel=$y$,
every axis x label/.style={at={(current axis.right of origin)},anchor=north east,xshift=1mm},
every axis y label/.style={at={(current axis.above origin)},anchor=north east,yshift=1mm},
xmin=-0.2,ymin=-0.15,
xmax=1.5,ymax=1.5,
%xtick={1},ytick={1},
restrict y to domain=0:1.2,
height=6cm,width=5cm,
enlargelimits=false]
\node[below left,black] at (axis cs:0,0) {$O$};
\addplot[name path global=x2,blue,smooth,samples=500,domain=0:1.2] %
{x^2} node[pos=0.75,sloped,yshift=-6pt]{$y=x^2$};
\addplot[name path global=genx,red,smooth,samples=500,domain=0:1.2] %
{sqrt(x)} node[pos=0.75,sloped,yshift=6pt]{$x=y^2$};
\def\vlvalue{0.4}; %x interval:[x,x+dx]
\def\intvlen{0.1}; %dx
\path[draw=none,name path=lx] (axis cs:\vlvalue,0)--(axis cs:\vlvalue,1.2); %x
\path[draw=none,name path=ldx] (axis cs:\vlvalue+\intvlen,0)--(axis cs:\vlvalue+\intvlen,1.2);%x+dx
%
\path[name intersections={of=x2 and lx,name=k}] (axis cs:\vlvalue,0)--(k-1);
\path(k-1) \pgfextra{\pgfgetlastxy{\kx}{\ky} %%no ;
\global\let\kx\kx %
\global\let\ky\ky};
\draw[blue,dashed] (axis cs:\vlvalue,0)--(\kx,\ky);
\path[name intersections={of=genx and lx,name=m}] (axis cs:\vlvalue,0)--(m-1);
\path(m-1) \pgfextra{\pgfgetlastxy{\mx}{\my} %%no ;
\global\let\mx\mx %
\global\let\my\my};
%draw from (k-1) to (\vlvalue+\intvlen,\ky)
\draw[red] (\kx,\ky)--(axis cs:\vlvalue+\intvlen,\ky); % % %wrong \ky
%draw rectangle
\fill[cyan!5] (k-1) rectangle (axis cs:\vlvalue+\intvlen,\my); % %wrong \my
\end{axis}
\end{tikzpicture}
\end{document}

\fill[cyan!5] (k-1) rectangle (axis cs:\vlvalue+\intvlen,\my);– huizhan wang Dec 09 '13 at 12:34