# TikZ Function Number Too Big

I want to draw two beta distributions comparing a prior and posterior distribution but it seems that the coefficients are too large for LaTeX? How do I fix it without changing the function? It has a few errors including Dimension too large and Number too big.

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{qqccqq}{rgb}{0,0.8,0}
\definecolor{qqttcc}{rgb}{0,0.2,0.8}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=8.333333333333332cm,y=1.0cm]
\draw[->,color=black] (-0.1,0) -- (1.1,0);
\foreach \x in {,0.2,0.4,0.6,0.8,1}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[color=black] (1.04,0.04) node [anchor=south west] { $\theta$};
\draw[->,color=black] (0,-0.5) -- (0,5.5);
\foreach \y in {,1,2,3,4,5}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-0.1,-0.5) rectangle (1.1,5.5);
\draw[dash pattern=on 1pt off 1pt,color=qqttcc, smooth,samples=100,domain=8.000000000003847E-7:0.9999990727280006] plot(\x,{3682570000*(1-(\x))^(10.67)*(\x)^(21.49)});
\draw[color=qqccqq, smooth,samples=100,domain=8.000000000003847E-7:0.9999990727280006] plot(\x,{2120.93*(1-(\x))^(2.67)*(\x)^(9.49)});
\draw (0.49,4.17) node[anchor=north west] {$g(\theta|D)$};
\draw (0.89,3.23) node[anchor=north west] {$g(\theta)$};
\end{tikzpicture}
\end{document}

• This always happens to me! I want an answer to this. – Ryan Reich Apr 6 '13 at 16:17
• – Marco Daniel Apr 22 '13 at 19:32
• For this question is a duplicated one. I can't vote because this question has an open bounty. – Marco Daniel Apr 22 '13 at 19:56
• In order to stick with plain tikz, you may want to consider using either the fixedpointarithmetic library of the fpu library. Both come with tikz and both allow to rescale every value by some prescribed amount. Perhaps that fixes the problem after some trial and error. If not, you may have bad luck unless you rely on other non-tikz solutions. – Christian Feuersänger Apr 23 '13 at 20:07

Consider also an Asymptote option, as it's quite powerful in graph drawing, especially when there is an array of curves. An example below organizes functions in array; other properties like color, width, label etc can be organized in arrays as well to be drawn in one loop. Also, the y-coordinate of the label is calculated as a point on the curve. asy-plot.tex

\documentclass{standalone}
\usepackage{lmodern}
\usepackage[inline]{asymptote}
\begin{document}
\begin{asy}
import graph;
size(250,170,IgnoreAspect);
real xMin=8.000000000003847e-7;
real xMax=0.9999990727280006;
int n=100;

typedef real Func(real x);

Func[] f={
new real(real x){return 3682570000*(1-x)^(10.67)*x^(21.49);},
new real(real x){return 2120.93*(1-x)^2.67*x^9.49;},
};

pen dashed=linetype(new real[] {4,3}); // set up dashed pattern

pen[] curvePen={rgb(0,0.8,0)+dashed,rgb(0,0.2,0.8),};
real[] curveWidth={1.6pt,2pt};
Label[] lab={
Label("$g(\theta\,\vert D)$",(0.6,f[0](0.6))),
Label("$g(\theta)$",(0.9,f[1](0.9))),
};

for(int i=0;i<f.length;++i){
draw(graph(f[i], xMin ,xMax ,n),curvePen[i]+curveWidth[i]);
label(lab[i],UnFill(2pt));
}

xaxis("",0,1.049,RightTicks(Step=0.1,step=0.05),EndArrow);
yaxis("",0,5-0.15,LeftTicks(Step=1,step=0.5),EndArrow);
\end{asy}
\end{document}


To process it with latexmk, create file latexmkrc:

sub asy {return system("asy '$_[0]'");} add_cus_dep("asy","eps",0,"asy"); add_cus_dep("asy","pdf",0,"asy"); add_cus_dep("asy","tex",0,"asy");  and run latexmk -pdf asy-plot.tex. The result looks like • Never heard of this package, but it looks nice. – Ryan Reich Apr 6 '13 at 20:06 • I tried to export my graph in asymptote package but the code generated just seemed wrong. I could tell what bit of the code did what and there was no preamble so I didn't know what packages and such it needed. Looks nice though! – DannyBland Apr 8 '13 at 11:56 • @DannyBland: What kind of software have you used for the export? Perhaps, the export was in a standalone asy file form, which has to be processed with asy -f pdf file.asy to get file.pdf to include it into LaTeX document. – g.kov Apr 9 '13 at 5:12 • @g.kov I use Geogebra. – DannyBland Apr 9 '13 at 16:38 • @DannyBland: Right, Geogebra exports a pure Asymptote code, for some reason adding .tex extension, when it should be .asy. Asymptote does not care much about extension, but it's better to rename the exported file to, say, example.asy and run asy example.asy to get example.eps or asy -f pdf example.asy to get example.pdf. – g.kov Apr 10 '13 at 3:39 Not a direct answer but I would use pgfplots for this. Maybe turning on the fpu library at the right point, might solve the problem but you don't need to draw any axis etc. so I think this is much more convenient. \documentclass{standalone} \usepackage{pgfplots} \usetikzlibrary{arrows} \definecolor{qqccqq}{rgb}{0,0.8,0} \definecolor{qqttcc}{rgb}{0,0.2,0.8} \begin{document} \begin{tikzpicture}[line cap=round,line join=round] \begin{axis}[ axis lines=middle, every inner x axis line/.append style={-triangle 45}, every inner y axis line/.append style={-triangle 45}, enlargelimits] \addplot[dash pattern=on 1pt off 1pt,color=qqttcc, smooth,samples=100,domain=8.000000000003847E-7:0.9999990727280006] plot(\x,{3682570000*(1-(\x))^(10.67)*(\x)^(21.49)}); \addplot[color=qqccqq, smooth,samples=100,domain=8.000000000003847E-7:0.9999990727280006] plot(\x,{2120.93*(1-(\x))^(2.67)*(\x)^(9.49)}); \node at (axis cs:0.49,4.17) {$g(\theta|D)$}; \node at (axis cs:0.89,3.23) {$g(\theta)\$};
\end{axis}
\end{tikzpicture}
\end{document}


The problem related to your edit is that the numbers become too small towards the end of the domain. To show that I've switched to the logarithm axis on y axis. TeX cannot handle that precision but the fpu library of TikZ or pgfplots by default can handle up to some extent and exits with divide by zero error. Otherwise pgfplots allows for gnuplot directives to be executed outside of TeX. Please check the manual of pgfplots Also you don't need to define everycolor you use. xcolor is a pretty powerful package so you can use color mixing capabilities. Here is a minimal example without any axis settings etc. to show how easy to use:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{semilogyaxis}

• @DannyBland What is not working exactly? We are trying to point out that there is a fundamental obstacle. See the duplicate Marco Daniel refers to. You can't get that precision out of TikZ without fpu recoding – percusse Apr 22 '13 at 21:01