# pgf math error, division by zero

I have a valid gnuplot function (plots fine in gnuplot), with pgfplots fails to use:

\documentclass{article}

\usepackage{graphicx}
\usepackage{pgfplots}

\begin{document}
\begin{figure}[H]
\pgfplotsset{width=0.8\textwidth, height=0.6\textwidth}
\pgfplotsset{samples=200}
\centering
\begin{tikzpicture}
\begin{axis}[mark=none, style=solid,
enlargelimits=false,
xmin=0,xmax = 2.5,
ymin=0,ymax = 2.5]
%
%
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}


The error is

PGFPlots: reading {testplots.pgf-plot.table}
! Package pgfplots Warning: Axis range for axis y is approximately empty; enlarging it (it is [0.0:0.0])
! Package PGF Math Error: You've asked me to divide 231.00105000000000' by 0.0', but I cannot divide any number by 0.0'.

-
If you provide the key domain=0:2.5 it works without any errors. –  percusse Oct 15 '12 at 21:39
@percusse An answer? –  egreg Oct 15 '12 at 22:07
@egreg Maybe but I still couldn't find why that particular number. –  percusse Oct 15 '12 at 22:09
@percusse The default domain is -5:5 and the value of the function at -5 is more than 10^56. I guess this has something to do with the weird error. –  egreg Oct 15 '12 at 22:14

The quick fix is to stay away from the part that makes the data explode. Hence if you provide the key domain=0:2.5 it works without any errors.

Initially I thought: The problem comes from the fact that the default domain of plotting the functions is ( as egreg mentioned) [-5,5]. Since negative numbers make the exponential term explode, (the first instance gives e^125 ).

However it gets weirder which makes me think that this is not just an overflow problem. For example starting from -5, using domain=-5:2 it gives the mentioned error but when this key is given as domain=-2.4:2 up to domain=-2.369:2 it gives this

\pgfplotsset{width=0.8\textwidth, height=0.6\textwidth}
\pgfplotsset{samples=200}

\begin{tikzpicture}
\begin{axis}[no marks, style=solid,
enlargelimits=false,
xmin=-5,xmax = 2.5,
ymin=0,ymax = 5,domain=-2.369:2]
%
%
\end{axis}
\end{tikzpicture}


Notice how the ymax is violated. Also if I try to increase the ymax value, it gives me a Dimension too large error. Even weirder, it starts to give Dimension too large error when we go past -2.369 towards higher values. But if I remove the ymax option completely I get

So after seeing that I've removed the ymax and let the original code run and I get surprisingly.

I guess something is choked during the axis limit calculation. So it might be a bug or an internal limitation.

-
This is not really related to the problem at hand, but all those graphs hide the behavior of this function around domain=0:2 (with ymin=0, ymax=2`). Might be useful to show that graph, or at least point that out. –  Peter Grill Oct 15 '12 at 23:20
@PeterGrill Oops forgot to include my own comment to the question :) thanks. –  percusse Oct 15 '12 at 23:22
Do you mean by your text that pgfplots has a possible bug? –  Matthias Pospiech Oct 16 '12 at 16:08
@MatthiasPospiech Might be but I'm not sure. It might just be due to the huge numbers too. –  percusse Oct 16 '12 at 18:30