3

I'm trying to plot a Gauss function/normal distribution, based on the answer to this question, however my domain is 0:10000 and the sample size is 95. This is resulting on the following error:

Dimension too large.

\pgfmathfloatexp@@ ...}\pgf@xa =\pgfmathresult pt 
                                                  \pgf@xa =0.434294481\pgf@x...
l.27   \addplot {gauss(4,0.5)};

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

I tried the answer to this question, but it didn't solve the problem.

Here's a MWE:

\documentclass[a4paper]{abntex2}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}

\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{figure}
\centering
\begin{tikzpicture}


\begin{axis}[every axis plot post/.append style={
  mark=none,domain=0:1000,samples=95,smooth}, % All plots: from -2:2, 50 samples, smooth, no marks
  axis x line*=bottom, % no box around the plot, only x and y axis
  axis y line*=left, % the * suppresses the arrow tips
  enlargelimits=upper,
  restrict y to domain=0:10
  ] % extend the axes a bit to the right and top
  \addplot {gauss(9043.1578947369,1)};
\end{axis}


\end{tikzpicture}
\caption{Tempos de deliberação por partida} \label{montecarlodist1}
\end{figure}



\end{document}
2
  • 2
    If the unit is 1 cm, then 10000 is 100 m. Are you expecting this? Shouldn't it be x domain to 95 and samples 10000? Jun 13, 2016 at 19:57
  • It's 10,000 miliseconds and 95 samples
    – Tuma
    Jun 15, 2016 at 18:25

1 Answer 1

3

This is due to a bug in pgfplots. I will take care that it gets addressed eventually.

The problem is that the numbers are so close to 0 that the TeX-based arithmetic runs into some number range issues (while computing the intermediate result of exp(-4.08893e7)).

That said, the argument domain=0:1000 for you function in question does not contain anything but "0". You could as well write \addplot {0} with the same visual output.

That said, I see the following possible workarounds:

  1. Use \addplot {0} instead of the exponential function or

  2. Fix the domain such that it shows relevant (non-zero) portions of the graph or

  3. come back once this issue has been fixed in pgfplots or

  4. If you really need to plot the plot as-is and you can make use of luatex, use the following equivalent formulation and compile it with lualatex

:

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\begin{document}

\tikzset{
    declare function={
      gauss(\m,\s)=1/(\s*sqrt(2*pi))*exp(-((x-\m)^2)/(2*\s^2));%
    }
}

\begin{tikzpicture}


\begin{axis}[every axis plot post/.append style={
  mark=none,domain=0:1000,samples=95,smooth}, % All plots: from -2:2, 50 samples, smooth, no marks
  axis x line*=bottom, % no box around the plot, only x and y axis
  axis y line*=left, % the * suppresses the arrow tips
  enlargelimits=upper,
  %restrict y to domain=0:10
  ] % extend the axes a bit to the right and top
  \addplot {gauss(9043.1578947369,1)};
\end{axis}


\end{tikzpicture}
\end{document}

(Differences to your picture: compat=1.13 activates the lua backend, the declare function syntax allows the computation to be done entirely in lua arithmetics, and restrict y to domain currently disables the lua backend, so I uncommented it.)

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .