# Placing text inside graphs using pgfplot

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)]
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}

• add clip=false in the {axis} options – vrleboss Jun 18 '13 at 19:07
• instead of putting two nodes for your two line of text, you could write: \node[red,above,text width = 3cm] at (axis cs:102,12.9){\small{'12 MTT\\65nm CMOS}}; See: tex.stackexchange.com/questions/119366/… – vrleboss Jun 18 '13 at 20:08

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)]
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}

• @vrleboss: Because the plots will still be clipped. Try setting xmax=180 in both solutions. – Jake Jun 18 '13 at 19:54

It seems that you are splitting your nodes in two to have the text on two lines.

To do so you could use the method described here: tikz alignment for multi-line text within font commands to get your node text on multiple lines.

Also you could use the pin option of the nodes: (you can find nice examples here: pgf(plots) node shadow/opaque pin)

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

\begin{document}
\begin{tikzpicture}[domain=0:3]
\begin{axis}[xlabel=Frequency(GHz), ylabel=Output Power(dBm)]
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[style={fill=blue,circle,inner sep=0pt,minimum size=4pt},pin={[text=red,text width=3cm,pin edge={black,thick}]180-45:{\small{'12 MTT\\65nm CMOS}}}] at (axis cs:102,12.9) { };
\node[style={fill=blue,circle,inner sep=0pt,minimum size=4pt},pin={[text=red,text width=3cm,pin edge={black,thick}]45:{\small{'12 MWCL\\0.13$\mu$m CMOS}}}] at (axis cs:130,7.7){ };

}
}

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


• How do you set the pin edge length? – JFernan Dec 5 '16 at 17:31