[Tex/LaTex] Placing text inside graphs using pgfplot

pgfplotstikz-pgf

My node markers disappear using this code. Is there a better way to do this?

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[domain=0:3]
\begin{axis}[xlabel=Frequency(GHz), ylabel=Output Power(dBm)]
\addplot[color=blue,only marks]
  table[x=x,y=y] {
x         y        
100  12.9        
130  7.7     
140  8
144  5     
150  6.3 
150  12.2 
213  -3.2        

};
\node[red,above] at (axis cs:102,12.9){\small{'12 MTT}};
\node[red,below] at (axis cs:104,12.9){\small{65nm CMOS}};

\node[red,left] at (axis cs:130,7.7){\small{'12 MWCL}};
\node[red,below left] at (axis cs:130,7.7){\small{0.13$\mu$m CMOS}};

\end{axis}
\end{tikzpicture}
\end{document}

Best Answer

The quick fix would be to set either clip=false or clip mode=individual in the axis options. However, this can have undesired effects if your plot data exceeds the axis limits or if you have several plots with lines and markers.

The "proper" way would be to wrap the \node commands in \pgfplotsset{after end axis/.append code={ ... } }. That way, the commands will be executed after the clip path has been deactivated.

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[xlabel=Frequency(GHz), ylabel=Output Power(dBm)]
\addplot[color=blue,only marks]
  table[x=x,y=y] {
x         y        
100  12.9        
130  7.7     
140  8
144  5     
150  6.3 
150  12.2 
213  -3.2        

};


\pgfplotsset{
    after end axis/.code={
        \node[red,above] at (axis cs:102,12.9){\small{'12 MTT}};
        \node[red,below] at (axis cs:104,12.9){\small{65nm CMOS}};

        \node[red,left] at (axis cs:130,7.7){\small{'12 MWCL}};
        \node[red,below left] at (axis cs:130,7.7){\small{0.13$\mu$m CMOS}};    
    }
}

\end{axis}

\end{tikzpicture}
\end{document}
Related Question