# tikz/pgf error, when I generate code from app to draw a graph

I'm coding for my teaching documents, and I use code which is generated from GeoGebra to draw a graph as follows:

\documentclass[12pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.}
\definecolor{wwwwww}{rgb}{0.4,0.4,0.4}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\begin{axis}[
x=1.0cm,y=1.0cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-0.2901348036393358,
xmax=4.048918344454138,
ymin=-2.091608455550902,
ymax=2.134742013371305,
xtick={-0.0,1.0,...,4.0},
ytick={-2.0,-1.0,...,2.0},]
\clip(-0.2901348036393358,-2.091608455550902) rectangle (4.048918344454138,2.134742013371305);
\draw[line width=2.pt,color=wwwwww,smooth,samples=100,domain=3.241610824052039E-7:4.048918344454138] plot(\x,{ln((\x))/ln(3.0)});
\draw[line width=2.pt,color=zzttqq,smooth,samples=100,domain=3.241610824052039E-7:4.048918344454138] plot(\x,{ln((\x))/ln(1.0/3.0)});
\begin{scriptsize}
\draw[color=wwwwww] (0.13813537721144858,-5.376891553393098) node {$f$};
\draw[color=zzttqq] (0.1494056451285745,4.371890194920794) node {$g$};
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}


Which produces the following error:

("C:\Program Files\MiKTeX 2.9\tex\latex\jknappen\ursfs.fd")
! Missing number, treated as zero.
<to be read again>
n
l.25 \end{axis}

?


This is another graph with a different domain bound which works correctly:

\documentclass[12pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}

\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
\definecolor{ccqqqq}{rgb}{0.8,0.,0.}
\definecolor{wwwwww}{rgb}{0.4,0.4,0.4}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\begin{axis}[
x=1.0cm,y=1.0cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-2.103964335355303,
xmax=2.0857704070948735,
ymin=-0.22178309134480115,
ymax=4.082514710469228,
xtick={-2.0,-1.0,...,2.0},
ytick={-0.0,1.0,...,4.0},]
\clip(-2.103964335355303,-0.22178309134480115) rectangle (2.0857704070948735,4.082514710469228);
\draw[line width=0.4pt,color=wwwwww,smooth,samples=100,domain=-2.103964335355303:2.0857704070948735] plot(\x,{2.0^((\x))});
\draw[line width=0.4pt,color=ccqqqq,smooth,samples=100,domain=-2.103964335355303:2.0857704070948735] plot(\x,{(1.0/2.0)^((\x))});
\begin{scriptsize}
\draw [fill=uuuuuu] (0.,1.) circle (2.0pt);
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}

• (1) welcome, (2) I don't think the domain likes scientific notation like that. – daleif Aug 24 '18 at 10:58
• @Max interesting. It can handle E-4 not E-5, bug report? – daleif Aug 24 '18 at 11:02
• May I suggest the OP to change the title of the question to something similar to pdfplots cannot handle 3E-7 in domain option plus tag the question with the pdfplots tag, then it will be easier to find for those who know alot about tikz/PGF. I can make the changes, but will not do so without the permission of the poster – daleif Aug 24 '18 at 11:16
• OP: I still suggest changing the title to something that is more appropriate to the question. Perhaps move the text you have in the title into the question instead, and use a title that others in the future with the same problem might hit when they search. BTW: if you use @name you can alert the person you are answering. – daleif Aug 24 '18 at 11:32
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Sep 19 '18 at 9:43

## 2 Answers

The problem is due to the lower bound of the domain in \draw which is too close to zero (3.241610824052039E-7). You can consider a slightly bigger range by modifying the bound to 3.241610824052039E-4 as follows:

\draw[line width=2pt,color=wwwwww,smooth,samples=100,domain=3.241610824052039E-4:4.048918344454138] plot(\x,{ln((\x))/ln(3.0)});
\draw[line width=2pt,color=zzttqq,smooth,samples=100,domain=3.241610824052039E-4:4.048918344454138] plot(\x,{ln((\x))/ln(1.0/3.0)});


which yields the following output.

• Oh thank you a lot! Can you give me some advise when I get this kind of trouble again? – Hoàng Duy Anh Aug 24 '18 at 13:02
• Just try to understand what the error is and test each part of your code separately and find what is causing the error exactly. Sometimes, a comma can make your output full of errors! Besides, if my solution responds to your question, please upvote and set as answer. – Sina Ahmadi Aug 24 '18 at 14:40

i'm not familiar with GeoGebra, but resulted code is terrible ... number of decimal digits at all numbers are excessively large

the same result you can obtain with simpler code write directly with help of the pgfplots package. the code is quite simple :-) :

\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}

\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.}
\definecolor{wwwwww}{rgb}{0.4,0.4,0.4}
\begin{tikzpicture}[
fl/.style={right,font=\footnotesize,text=zzttqq}
]
\begin{axis}[
x=1.0cm,y=1.0cm,
axis lines=middle,
x axis line style={shorten < =-3mm},
grid= major,
xmin= 0,    xmax= 4.5,
ymin=-2.2,  ymax= 2.2,
restrict y to domain=-2:2,
xtick={0,...,4},
%
smooth,
samples=500,
domain=0.01:4,
no marks
]
\addplot +[line width=2pt] {ln(x)/ln(3)}   node[fl] {$g$};
\addplot +[line width=2pt] {ln(x)/ln(1/3)} node[fl] {$f$};
\end{axis}
\end{tikzpicture}
\end{document}


• Can you share me some document write about drawing the same graph like you?? – Hoàng Duy Anh Aug 24 '18 at 12:56
• @HoàngDuyAnh,"Manual for Package pgfplots" which is part of pgfplots installation. many examples you can find on pgfplots.net and here on site. – Zarko Aug 24 '18 at 13:01