I constructed a macro to annotate slopes of graphs by means of triangles in a loglogaxis. It works fine for small slopes, but for large slopes I get a Dimension too large error.
Minimum working example:
\documentclass[margin=1cm]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{calc}
%%% START MACRO FOR ANNOTATION OF TRIANGLE WITH SLOPE %%%.
\newcommand{\logLogSlopeTriangle}[5]
{
% #1. Relative offset in x direction.
% #2. Width in x direction, so xA-xB.
% #3. Relative offset in y direction.
% #4. Slope d(y)/d(log10(x)).
% #5. Plot options.
\pgfplotsextra
{
\pgfkeysgetvalue{/pgfplots/xmin}{\xmin}
\pgfkeysgetvalue{/pgfplots/xmax}{\xmax}
\pgfkeysgetvalue{/pgfplots/ymin}{\ymin}
\pgfkeysgetvalue{/pgfplots/ymax}{\ymax}
% Calculate auxilliary quantities.
\pgfmathsetmacro{\xA}{(exp(\xmin))^(1-#1)*(exp(\xmax))^#1}
\pgfmathsetmacro{\yA}{(exp(\ymin))^(1-#3)*(exp(\ymax))^#3}
\pgfmathsetmacro{\xB}{(exp(\xmin))^(1-(#1-#2))*(exp(\xmax))^(#1-#2)}
\pgfmathsetmacro{\yB}{\yA}
\pgfmathsetmacro{\xC}{\xA}
\pgfmathsetmacro{\yC}{\yA/(\xB^#4)*\xA^#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)-- node[pos=0.5,anchor=north] {1}
(B)--
(C)-- node[pos=0.5,anchor=west] {#4}
cycle;
}
}
%%% END MACRO FOR ANNOTATION OF TRIANGLE WITH SLOPE %%%.
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}
[
xlabel=$x$,
ylabel style={rotate=-90},
ylabel=$y$,
grid=major,
clip=false
]
\addplot[blue,line width=1pt,domain=10^1:10^2] {sqrt(x)};
\addplot[red,line width=1pt,domain=10^1:10^2] {x};
%\addplot[green!75!black,line width=1pt,domain=10^1:10^2] {x^3}; % RESULTS IN A 'DIMENSION TOO LARGE ERROR. HOW DO I FIX THIS?'
\logLogSlopeTriangle{0.9}{0.1}{0.1}{0.5}{blue};
\logLogSlopeTriangle{0.75}{0.1}{0.1}{1}{red};
%\logLogSlopeTriangle{0.6}{0.1}{0.1}{3}{green!75!black}; % RESULTS IN A 'DIMENSION TOO LARGE ERROR. HOW DO I FIX THIS?'
\end{loglogaxis}
\end{tikzpicture}
\end{document}
Result:

Uncommenting the \addplot ... {x^3} and its corresponding annotation \logLogSlopeTriangle{...}, I get the Dimension too large error.
How do I fix this?

poskey. – percusse May 18 '15 at 10:27rel axis csinstead ofaxis cs? In this way, the dimensions need not be so large. What do you think? – Adriaan May 18 '15 at 11:04pgfplotsparsing of the numbers. Hereexp(\ymax)ise^15.08112and that is way too big for TeX. You can switch tofpulibrary for handling big numbers but stillrel axis csoraxis direction csis a better way indeed. – percusse May 18 '15 at 11:12rel axis cs, see my answer below. I hope you like it. – Adriaan May 19 '15 at 09:48