# How can I improve the drawing of Thomae's function? [closed]

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:

1. I prefer the image to have more details, as the one I saw you.
2. I don't want the space between x-dots and upper-dots.

1. 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?

• You have discovered a bug in the update of TikZ, thanks for spotting it. gcd does 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. – user121799 Jul 11 at 12:59
• The bug has been resolved by Henri Menke, see github.com/pgf-tikz/pgf/issues/706, where you can find a temporary fix. With this fix decreasing the gap is as simple as increasing upper bound of the loop domain, e.g. \foreach \X [evaluate=\X as \Ymax using {int(\X-1)}]in {55,54,...,2}. – user121799 Jul 11 at 21:51