I tried to parameterize my previous question, by defining a new command, however, the result isn't as I expected. So, what is wrong/missing here?
Additionally, since I need to apply this command to many plots with different y scales, how can I make the arrow height a percentage or fraction of the whole plot height instead of positioning it at certain y value?
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{arrows.meta}
\tikzset{
IntervalLine/.style={
draw=black,
line width=1pt
},
IntervalArrow/.style={
blue,
very thick,
{Stealth}-{Stealth}
}
}
\newcommand{\AnnotateInterval}[3]{
\begin{tikzpicture}
\draw[IntervalLine] (#1, \pgfkeysvalueof{/pgfplots/ymin}) -- (#1, \pgfkeysvalueof{/pgfplots/ymax});
\draw[IntervalLine] (#2, \pgfkeysvalueof{/pgfplots/ymin}) -- (#2, \pgfkeysvalueof{/pgfplots/ymax});
\draw[IntervalArrow] (#1,2) -- node[above,align=center]{#3} (#2,2);
\end{tikzpicture}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=5]
\addplot[mark=none,blue] {x^2};
\AnnotateInterval{2}{4}{some text}
\end{axis}
\end{tikzpicture}
\end{document}

AnnotateIntervalnewcommand. – Stefan Pinnow Apr 17 '17 at 15:48