In the minimum working example below I use the keys xmin, xmax, ymin and ymax for calculations of coordinates for annotations. However, this only works when the axis limits are set explicitly in the axis options.
I also want the code to work when I do not explicitly set the axis limits. In what key names are the axis limits stored in that case?
Minimum working example:
% Mind section '4.17 Custom annotations' of the PGFplots manual Revision 1.12 (2015/01/31).
\documentclass[margin=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{calc}
\newcommand{\slopeTriangle}[9]
{
% Calculate auxilliary quantities.
\pgfmathsetmacro{\xA}{#6+(#1+#2)*(#7-#6)}
\pgfmathsetmacro{\yA}{#8+#3*(#9-#8)}
\pgfmathsetmacro{\xB}{#6+#1*(#7-#6)}
\pgfmathsetmacro{\yB}{\yA}
\pgfmathsetmacro{\xC}{\xA}
\pgfmathsetmacro{\yC}{\yA+(\xA-\xB)*#4}
% Define coordinates for \draw.
\coordinate (A) at (axis cs:\xA,\yA);
\coordinate (B) at (axis cs:\xB,\yB);
\coordinate (C) at (axis cs:\xC,\yC);
% Draw slope triangle.
\draw[#5] (A)--(B) node[pos=0.5,anchor=north] {1};
\draw[#5] (B)--(C);
\draw[#5] (C)--(A) node[pos=0.5,anchor=west] {1};
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
xtick={-0.1,0,1,1.1},
xmin=-0.1, % WHAT IF I REMOVE THIS?
xmax=1.1, % WHAT IF I REMOVE THIS?
xlabel=$x$,
ytick={-0.2,0,2,2.2},
ymin=-0.2, % WHAT IF I REMOVE THIS?
ymax=2.2, % WHAT IF I REMOVE THIS?
ylabel style={rotate=-90},
ylabel=$y$,
unit vector ratio=2 1 1,
clip=false
]
\addplot[blue,domain=0:1] {x};
\addplot[red,domain=0:1] {2*x};
\pgfkeysgetvalue{/pgfplots/xmin}{\xmin} % IF THE xmin IS NOT SET EXPLICITLY, THEN WHAT IS THE KEYNAME?
\pgfkeysgetvalue{/pgfplots/xmax}{\xmax} % IF THE xmax IS NOT SET EXPLICITLY, THEN WHAT IS THE KEYNAME?
\pgfkeysgetvalue{/pgfplots/ymin}{\ymin} % IF THE ymin IS NOT SET EXPLICITLY, THEN WHAT IS THE KEYNAME?
\pgfkeysgetvalue{/pgfplots/ymax}{\ymax} % IF THE ymax IS NOT SET EXPLICITLY, THEN WHAT IS THE KEYNAME?
\slopeTriangle{0.8}{0.1}{0.1}{1}{blue}{\xmin}{\xmax}{\ymin}{\ymax};
\end{axis}
\end{tikzpicture}
\end{document}

\pgfmathfloattofixed{\pgfplots@xmin}\xdef\xmin{\pgfmathresult}. However these numbers represent the limits of data instead of axis. – Symbol 1 May 13 '15 at 03:58\pgfplots@xmindoes not seem to exist. Did you perhaps test it? Can you perhaps change my minimum working example accordingly? In the meanwhile, I found out that the commandscurrent axis.south westandcurrent axis.north eastcould be useful in retrieving thexmin,xmax,yminandymax. However, I cannot seem to be able to extract thexandyfrom these current axis nodes. The answer as given in http://tex.stackexchange.com/questions/14021/extract-the-x-y-part-from-a-coordinate-in-pgfplots does not seem to work. – Adriaan May 13 '15 at 08:41