# Draw reduced graph with pgfplot

I want to reduce the information contained in a graph to the minimum. I started with a spectrum that I drew from a data file ( http://www.sendspace.com/file/wwydju ).

\documentclass{standalone}

\usepackage {tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}

\definecolor{myorange}{RGB}{238,165,52}

\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=none]
\addplot [color=myorange,style=solid, thick] table[x index=0,y index=1,col sep=space]{spectrum.dat};

\end{axis}

\end{tikzpicture}
\end{document}


But I don't really understand how I can access the points from the graph outside the axis-environment. I want to create something like this graph from Jean-luc Doumont's book Trees, Maps and Theorems (I know that I only have the interpolant if you want to put it that way).

How does the position of the graph relate to the normal coordinate axis?

If someone could help me out on that one I would be really grateful :).

• We also need the file 2micronNB.dat – WillAdams Jul 25 '13 at 16:18
• i will upload it tmw, i dont have access to the file right now. – spookyfw Jul 25 '13 at 22:54

If I understand correctly, you're asking how you can place TikZ elements like nodes or arrows using axis units. An easy way to do this is to include the elements within the axis environment, because this gives you access to the axis cs: coordinate system: If you want to place an element at 17.2 GHz, 650 mW, you would say \node at (axis cs:17.2,650) ..., for instance.

If you say clip mode=individual in the axis options, then the TikZ objects are not restricted to the axis area.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{siunitx}
\pgfmathsetseed{1}

\begin{document}
\begin{tikzpicture}[
declare function={lorentz(\x,\w)=\w^2/(\w^2+(2*\x)^2);}
]
\begin{axis}[
axis lines*=left,
xtick={16,17.2,19},
ytick={0,325,650},
ymin=0, ymax=650,
enlarge y limits=false,
enlarge x limits=false,
width=10cm, height=5cm,
xlabel=Frequency in \si{\GHz},
ylabel=Output power\\in \si{\milli\W},
ylabel style={
rotate=-90,
align=right,
},
tick align=outside,
tick style=black,
clip mode=individual,
x axis line style={opacity=0},
x tick style={yshift=-0.5cm},
x tick label style={yshift=-0.5cm},
y axis line style={xshift=-0.5cm},
y tick style={xshift=-0.5cm},
y tick label style={xshift=-0.5cm}
]
thick,
orange,
smooth,
samples=30,
domain=15.5:19.5
] {lorentz(x-17.2,0.63)*650};
only marks,
samples=20,
domain=16:19
] {lorentz(x-17.2,0.63)*650+rand*20};

\draw [thick, gray, latex-latex] (axis cs:16.885,325) -- (axis cs:17.515,325)
node [black!75, pos=0.5, below] {\SI{630}{\MHz}};

\node at (axis cs:17.3,660) [anchor=west] {measured};
\node at (axis cs:17.35,550) [anchor=west, orange!90!black] {calculated};

\draw [yshift=-0.5cm] ({rel axis cs:0,0}-|{axis cs:16,0}) -- ({rel axis cs:0,0}-|{axis cs:19,0});
\end{axis}
\end{tikzpicture}
\end{document}

• haha..that looks quite good already. thanks for your input. You are right, I was too obsessed in doing it outside of the axis-environment. It seems to work like this. I will try to incorporate your code tmw. – spookyfw Jul 25 '13 at 22:59
• If you compare the example and your solution: you are bound to the position of the axis. Thats why I thought that it would be nice to get out of the environment to gain full control. This doesn't seem to work \draw ({rel axis cs:0,0}-|{axis cs:16,-1}) -- ({rel axis cs:0,0}-|{axis cs:19,-1}); I would like to get more space between graph and axis as in the example. Any possibility to access the data points from outside the axis environment? – spookyfw Jul 26 '13 at 9:35
• @spookyfw: Not directly, no, because of the scaling PGFPlots introduces (which is one of its great features. Normal TikZ wouldn't be able to handle large coordinate values). You could of course use \coordinate (A) at (axis cs:19,500); inside the axis and then use (A) outside the axis, but I think that's more pain than it's worth. If you want to be able to place TikZ elements outside the axis but still refer use the axis coordinates, you can set clip mode=individual. – Jake Jul 26 '13 at 11:11
• I don't really understond what this command is doing. I always thought that axis cs:x,x is accessing a whole line. When used alone it is just a point? cs just stands for coordinates? Clip mode=individual just allows accessing axis cs from outside the axis environment? I am asking because it didn't work for me ;). – spookyfw Jul 26 '13 at 12:40
• clip mode=individual allows TikZ elements that are specified within the axis to protrude past the axis limits. Normally, they would be clipped. cs stands for coordinate system, (axis cs:x,y) always refers to a single point. I'm not sure what you mean by "whole line". Could you give an example of what you tried to do that didn't work? – Jake Jul 26 '13 at 13:00