I 'm trying to draw Thomae's function (in black). I want the plot below.

enter image description here

I used marmot's code from here.

\draw [-stealth] (-0.1,0) -- (1.1,0);
\draw [-stealth] (0,-0.1) -- (0,0.6);
\foreach \X in {1,...,7}
\draw (0.02,1/\X) -- (-0.02,1/\X) node[left,xshift={(-(1+pow(-1,\X)))*3pt}]{$\frac{1}{\X}$};
\foreach \X [evaluate=\X as \Ymax using {int(\X-1)}]in {25,24,...,2}
{\foreach \Y in {1,...,\Ymax}
 \draw (\Y/\X,0.02) -- (\Y/\X,-0.02) node[below,fill=white]{$\frac{\Y}{\X}$};
 \draw[ultra thin] (\Y/\X,0.01) -- (\Y/\X,-0.01);
 \fill ({\Y/\X},1/\X) circle(0.2pt); 
\foreach \X in {0,1,...,80}
{\fill (\X/80,0) circle(0.2pt); }

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.

enter image description here

  1. If I use this code, I get an other (flat) image, than this I expected.

enter image description here

  • Is there any solutions for 1 and 2?
  • If it's not, what should I do with 3?

Thanks in advanced!

  • 2
    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
  • 2
    It has been reported officially: github.com/pgf-tikz/pgf/issues/706 – user121799 Jul 11 at 13:08
  • 1
    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
  • 1
    You're welcome! And sorry for the bug, and thanks for spotting it! – user121799 Jul 12 at 6:39
  • 4
    I'm voting to close this question as off-topic because the bug was corrected in the current version ... – Mensch Jul 15 at 21:10

Browse other questions tagged or ask your own question.