[Tex/LaTex] How to add a marker to TikZ plot for specific x coordinate?

pgfplots

Please take a look at my code. I am plotting values from a file and I want to add a marker at the x coordinate of 100 GHz.

\documentclass[convert={density=400,outext=.png}]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\begin{axis}[ymin=-30,ymax=10,enlargelimits=false,
title=Large Signal S-parameters of Pre-Amplifier, 
ylabel=S-parameters(dB),
xlabel=Frequency(GHz), 
legend style={legend pos= south east}, 
ytick={-30,-25,-20,-15,-10,-5,0,5,10},
grid=major]
\addplot +[smooth][mark=none, line width=1.5pt]
file{S21_preamp};
\addlegendentry{$S_{21}$}
\addplot +[smooth] [mark=none, line width=1.5pt]
file{S11_preamp};
\addlegendentry{$S_{11}$}
\draw [<-,thick](100,360) -- (120,370) node[above]{5.8dB} ;
\end{axis}
\end{tikzpicture}
\end{document}

Right now I have an arrow pointing to the x position. Is there a better way to do this?

Best Answer

You can use the axis coordinate system via (axis cs: x,y). I made up some sample data for testing. I also used a nicer arrow tip, you'll need the arrows library for that. Lastly for the tick labels you can use the {a,a+b,...,c} notation which will give you labels spaced b starting from a to c:

Code

\documentclass[convert={density=400,outext=.png}]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\begin{axis}
[   ymin=5,
    ymax=25,
    enlargelimits=false,
    title=Large Signal S-parameters of Pre-Amplifier, 
    ylabel=S-parameters(dB),
    xlabel=Frequency(GHz), 
    legend style={legend pos= south east}, 
    ytick={5,10,...,25},
    grid=major,
]
\addplot +[smooth][mark=none, line width=1.5pt] coordinates {(1,10)(2,8)(3,11)(4,13)(5,9)};
\addlegendentry{$S_{21}$}
\addplot +[smooth] [mark=none, line width=1.5pt] coordinates {(1,17)(2,20)(3,19)(4,21)(5,18)};
\addlegendentry{$S_{11}$}
\draw [stealth-,thick] (axis cs:3,11) -- (axis cs:3,15) node[above]{5.8dB} ;
\end{axis}
\end{tikzpicture}
\end{document}

Output

enter image description here