I 'm trying to draw Thomae's function (in black). I want the plot below.
I used marmot's code from here.
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=8]
\draw [-stealth] (-0.1,0) -- (1.1,0);
\draw [-stealth] (0,-0.1) -- (0,0.6);
\foreach \X in {1,...,7}
{\ifnum\X=1
\else
\draw (0.02,1/\X) -- (-0.02,1/\X) node[left,xshift={(-(1+pow(-1,\X)))*3pt}]{$\frac{1}{\X}$};
\fi
}
\foreach \X [evaluate=\X as \Ymax using {int(\X-1)}]in {25,24,...,2}
{\foreach \Y in {1,...,\Ymax}
{\ifnum\X<6
\draw (\Y/\X,0.02) -- (\Y/\X,-0.02) node[below,fill=white]{$\frac{\Y}{\X}$};
\else
\draw[ultra thin] (\Y/\X,0.01) -- (\Y/\X,-0.01);
\fi
\pgfmathtruncatemacro{\TST}{gcd(\X,\Y)}
\ifnum\TST=1
\fill ({\Y/\X},1/\X) circle(0.2pt);
\fi
}
}
\foreach \X in {0,1,...,80}
{\fill (\X/80,0) circle(0.2pt); }
\end{tikzpicture}
\end{document}
But I have 3 problems:
- I prefer the image to have more details, as the one I saw you.
- I don't want the space between x-dots and upper-dots.
- If I use this code, I get an other (flat) image, than this I expected.
- Is there any solutions for 1 and 2?
- If it's not, what should I do with 3?
Thanks in advanced!



pstricks? Thepst-funcpackage has a predefined\psThomaecommand, which plots the function. – Bernard Jul 11 '19 at 09:27pstricks, but I 'll try it! – Kώστας Κούδας Jul 11 '19 at 10:49gcddoes no longer work properly, try e.g.\documentclass[tikz,border=3.14mm]{standalone} \begin{document} \pgfmathparse{gcd(4,9)}\pgfmathresult \end{document}. I believe I know who made this change, and will try to fix it asap. – Jul 11 '19 at 12:59\documentclass[tikz,border=3.14mm]{standalone} \begin{document} \pgfmathparse{gcd(4,9)}\pgfmathresult \end{document}). Should I change something of the first code? – Kώστας Κούδας Jul 11 '19 at 15:31pdflatex, load alsoauto-pst-pdf(pdflatex doesn't understand the calculations of the postscript language) to have a shorter compilation chain, or compile with `xelatex`` . – Bernard Jul 11 '19 at 15:53\foreach \X [evaluate=\X as \Ymax using {int(\X-1)}]in {55,54,...,2}. – Jul 11 '19 at 21:51