Look at the following MWE:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}[]
\begin{axis}[
width=14cm, height=9cm,
xmin=-1, xmax=1,
ymin=0, ymax=5,
axis y line* = left,
xlabel = {Nivel $L$ (m)},
ylabel = {$y$},
samples = 100,
]
\addplot[thick, blue] {2.5*(4+x)-7.5};
\label{plot:lin}
\addplot[thick, red] {2.5*(4+0.7*x+0.3*x^3)-7.5};
\label{plot:nl}
\end{axis}
\begin{axis}[
width=14cm, height=9cm,
xmin=-1, xmax=1,
ymin=-1, ymax=1,
axis y line* = right,
axis x line* = none,
ylabel = {absolute error $\epsilon$ (m)},
samples = 100,
]
% http://tex.stackexchange.com/a/42752/38080
\addlegendimage{/pgfplots/refstyle=plot:lin}\addlegendentry{ideal}
\addlegendimage{/pgfplots/refstyle=plot:nl}\addlegendentry{real}
%
\addplot[thick, green] {2.5*(4+0.7*x+0.3*x^3)-2.5*(4+x)};
\addlegendentry{error}
\end{axis}
\end{tikzpicture}
\end{document}
When compiled, it gives a "dimension too large" error:
! Dimension too large.
<recently read> \pgf@yy
l.35 \end{axis}
[...]
?
! Dimension too large.
\pgfusepath ...@y by.5\pgflinewidth \ifdim \pgf@y
>\pgf@picmaxy \global \pgf...
l.35 \end{axis}
...but the graph comes out correctly.
What am I doing wrong?
PS: the problem seems height --- if it's more than 7cm, it chokes.

samples=100, but I didn't relate... thanks. Will accept as soon as I can. – Rmano May 07 '16 at 18:35