Graphing the Thomae Function











up vote
1
down vote

favorite












Could someone please give me guidance on how to plot this special function? I honestly have no idea where even to start (I've never actually done a tikzpicture from scratch).



[
f(x) = left{begin{array}{lr}
0, &x text{irrational}\
frac{1}{q}, &x = frac{p}{q} text{in lowest form}\[10pt]
end{array}right}


]



It should look something like this:



enter image description here










share|improve this question









New contributor




Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Do you want a cartoon as your this screen shot?AFAIK there are infinitely many rational numbers in the interval [0,1] so drawing the dots requires the specification of a cut-off for q, I think.
    – marmot
    4 hours ago










  • This is Thomae's function, sometimes called the popcorn function. It is built into the pst-func package, located here on CTAN. See page 66.
    – DJP
    4 hours ago















up vote
1
down vote

favorite












Could someone please give me guidance on how to plot this special function? I honestly have no idea where even to start (I've never actually done a tikzpicture from scratch).



[
f(x) = left{begin{array}{lr}
0, &x text{irrational}\
frac{1}{q}, &x = frac{p}{q} text{in lowest form}\[10pt]
end{array}right}


]



It should look something like this:



enter image description here










share|improve this question









New contributor




Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Do you want a cartoon as your this screen shot?AFAIK there are infinitely many rational numbers in the interval [0,1] so drawing the dots requires the specification of a cut-off for q, I think.
    – marmot
    4 hours ago










  • This is Thomae's function, sometimes called the popcorn function. It is built into the pst-func package, located here on CTAN. See page 66.
    – DJP
    4 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Could someone please give me guidance on how to plot this special function? I honestly have no idea where even to start (I've never actually done a tikzpicture from scratch).



[
f(x) = left{begin{array}{lr}
0, &x text{irrational}\
frac{1}{q}, &x = frac{p}{q} text{in lowest form}\[10pt]
end{array}right}


]



It should look something like this:



enter image description here










share|improve this question









New contributor




Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Could someone please give me guidance on how to plot this special function? I honestly have no idea where even to start (I've never actually done a tikzpicture from scratch).



[
f(x) = left{begin{array}{lr}
0, &x text{irrational}\
frac{1}{q}, &x = frac{p}{q} text{in lowest form}\[10pt]
end{array}right}


]



It should look something like this:



enter image description here







tikz-pgf






share|improve this question









New contributor




Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago





















New contributor




Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









Miguel Cumming-Romo

112




112




New contributor




Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Miguel Cumming-Romo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Do you want a cartoon as your this screen shot?AFAIK there are infinitely many rational numbers in the interval [0,1] so drawing the dots requires the specification of a cut-off for q, I think.
    – marmot
    4 hours ago










  • This is Thomae's function, sometimes called the popcorn function. It is built into the pst-func package, located here on CTAN. See page 66.
    – DJP
    4 hours ago


















  • Do you want a cartoon as your this screen shot?AFAIK there are infinitely many rational numbers in the interval [0,1] so drawing the dots requires the specification of a cut-off for q, I think.
    – marmot
    4 hours ago










  • This is Thomae's function, sometimes called the popcorn function. It is built into the pst-func package, located here on CTAN. See page 66.
    – DJP
    4 hours ago
















Do you want a cartoon as your this screen shot?AFAIK there are infinitely many rational numbers in the interval [0,1] so drawing the dots requires the specification of a cut-off for q, I think.
– marmot
4 hours ago




Do you want a cartoon as your this screen shot?AFAIK there are infinitely many rational numbers in the interval [0,1] so drawing the dots requires the specification of a cut-off for q, I think.
– marmot
4 hours ago












This is Thomae's function, sometimes called the popcorn function. It is built into the pst-func package, located here on CTAN. See page 66.
– DJP
4 hours ago




This is Thomae's function, sometimes called the popcorn function. It is built into the pst-func package, located here on CTAN. See page 66.
– DJP
4 hours ago










2 Answers
2






active

oldest

votes

















up vote
1
down vote













Here's a sagetex solution using the computer algebra system, SAGE, to do the computations.



documentclass[border=3pt]{standalone}
usepackage{sagetex}
usepackage{pgfplots}
pgfplotsset{compat=1.15}
begin{document}
begin{sagesilent}
xvalue =
yvalue =
for q in range(1,101):
for p in range(1,q):
xvalue += [(p*1.0/q*1.).n(digits=2)]
yvalue += [(1/(q/gcd(p,q))).n(digits=2)]
output = r""
output += r"begin{tikzpicture}"
output += r"begin{axis}["
output += r"title={Thomae's function},"
output += r"xlabel=$x$,"
output += r"ylabel=$f(x)$,"
output += r"]"
output += r"addplot[only marks,mark options={mark size=.5pt}] coordinates {"
for i in range(0,len(xvalue)):
output += r"(%s, %s)"%(xvalue[i],yvalue[i])
output += r"};"
output += r"end{axis}"
output += r"end{tikzpicture}"
end{sagesilent}
sagestr{output}
end{document}


The result running in Cocalc is shown below:
enter image description here



By changing the value of q from 101 to something more, you'll get more points. SAGE is not part of the LaTeX distribution, so you would need to install it on your computer or, to avoid that, get a free Cocalc account. The documentation for SAGE is here and the documentation for sagetex is here on CTAN. The SAGE programming involves a mixture of SAGE commands mixed into Python code. If your work involves mathematics, then this is a very convenient package to learn.






share|improve this answer




























    up vote
    1
    down vote













    Welcome to TeX.SE! Here is a proposal. Of course, this is just a cartoon because I had to cut off q, as is done in your screen shot.



    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,1.1);
    foreach X in {1,...,7}
    {ifnumX=1
    draw (0.02,1/X) -- (-0.02,1/X) node[left]{$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 {5,4,...,2}
    {foreach Y in {1,...,Ymax}
    {draw (Y/X,0.02) -- (Y/X,-0.02) node[below,fill=white]{$frac{Y}{X}$};
    fill ({Y/X},1/X) circle(0.2pt);
    }
    }
    end{tikzpicture}
    end{document}


    enter image description here



    ADDENDUM: Without external programs, compiles in below 1sec on a 4 years old MacBook pro.



    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}
    {ifnumX=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}
    {ifnumX<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
    fill ({Y/X},1/X) circle(0.2pt);
    }
    }
    foreach X in {0,1,...,80}
    {fill (X/80,0) circle(0.2pt); }
    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer























    • Your answer are excellent. Have you take the "virus" of the best users of LaTeX? :-):-). +1
      – Sebastiano
      4 hours ago










    • @Sebastiano Such a virus does not exist and I am certainly not the best user of LaTeX.
      – marmot
      4 hours ago










    • I hope you understand my line. I was joking; you're a very good, useless person to deny it.
      – Sebastiano
      4 hours ago










    • How would you suggest putting in dots on the x-axis? As shown in the screenshot
      – Miguel Cumming-Romo
      2 hours ago










    • @MiguelCumming-Romo Just add foreach X in {0,1,...,80} {fill (X/80,0) circle(0.2pt); } (you may replace 80 by some other number) as I did in my second example. To make the numbers irrational, you could shift the circles by a tiny irrational amount, but in the end none of the computer-generated numbers are irrational).
      – marmot
      2 hours ago













    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Miguel Cumming-Romo is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461603%2fgraphing-the-thomae-function%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Here's a sagetex solution using the computer algebra system, SAGE, to do the computations.



    documentclass[border=3pt]{standalone}
    usepackage{sagetex}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}
    begin{document}
    begin{sagesilent}
    xvalue =
    yvalue =
    for q in range(1,101):
    for p in range(1,q):
    xvalue += [(p*1.0/q*1.).n(digits=2)]
    yvalue += [(1/(q/gcd(p,q))).n(digits=2)]
    output = r""
    output += r"begin{tikzpicture}"
    output += r"begin{axis}["
    output += r"title={Thomae's function},"
    output += r"xlabel=$x$,"
    output += r"ylabel=$f(x)$,"
    output += r"]"
    output += r"addplot[only marks,mark options={mark size=.5pt}] coordinates {"
    for i in range(0,len(xvalue)):
    output += r"(%s, %s)"%(xvalue[i],yvalue[i])
    output += r"};"
    output += r"end{axis}"
    output += r"end{tikzpicture}"
    end{sagesilent}
    sagestr{output}
    end{document}


    The result running in Cocalc is shown below:
    enter image description here



    By changing the value of q from 101 to something more, you'll get more points. SAGE is not part of the LaTeX distribution, so you would need to install it on your computer or, to avoid that, get a free Cocalc account. The documentation for SAGE is here and the documentation for sagetex is here on CTAN. The SAGE programming involves a mixture of SAGE commands mixed into Python code. If your work involves mathematics, then this is a very convenient package to learn.






    share|improve this answer

























      up vote
      1
      down vote













      Here's a sagetex solution using the computer algebra system, SAGE, to do the computations.



      documentclass[border=3pt]{standalone}
      usepackage{sagetex}
      usepackage{pgfplots}
      pgfplotsset{compat=1.15}
      begin{document}
      begin{sagesilent}
      xvalue =
      yvalue =
      for q in range(1,101):
      for p in range(1,q):
      xvalue += [(p*1.0/q*1.).n(digits=2)]
      yvalue += [(1/(q/gcd(p,q))).n(digits=2)]
      output = r""
      output += r"begin{tikzpicture}"
      output += r"begin{axis}["
      output += r"title={Thomae's function},"
      output += r"xlabel=$x$,"
      output += r"ylabel=$f(x)$,"
      output += r"]"
      output += r"addplot[only marks,mark options={mark size=.5pt}] coordinates {"
      for i in range(0,len(xvalue)):
      output += r"(%s, %s)"%(xvalue[i],yvalue[i])
      output += r"};"
      output += r"end{axis}"
      output += r"end{tikzpicture}"
      end{sagesilent}
      sagestr{output}
      end{document}


      The result running in Cocalc is shown below:
      enter image description here



      By changing the value of q from 101 to something more, you'll get more points. SAGE is not part of the LaTeX distribution, so you would need to install it on your computer or, to avoid that, get a free Cocalc account. The documentation for SAGE is here and the documentation for sagetex is here on CTAN. The SAGE programming involves a mixture of SAGE commands mixed into Python code. If your work involves mathematics, then this is a very convenient package to learn.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        Here's a sagetex solution using the computer algebra system, SAGE, to do the computations.



        documentclass[border=3pt]{standalone}
        usepackage{sagetex}
        usepackage{pgfplots}
        pgfplotsset{compat=1.15}
        begin{document}
        begin{sagesilent}
        xvalue =
        yvalue =
        for q in range(1,101):
        for p in range(1,q):
        xvalue += [(p*1.0/q*1.).n(digits=2)]
        yvalue += [(1/(q/gcd(p,q))).n(digits=2)]
        output = r""
        output += r"begin{tikzpicture}"
        output += r"begin{axis}["
        output += r"title={Thomae's function},"
        output += r"xlabel=$x$,"
        output += r"ylabel=$f(x)$,"
        output += r"]"
        output += r"addplot[only marks,mark options={mark size=.5pt}] coordinates {"
        for i in range(0,len(xvalue)):
        output += r"(%s, %s)"%(xvalue[i],yvalue[i])
        output += r"};"
        output += r"end{axis}"
        output += r"end{tikzpicture}"
        end{sagesilent}
        sagestr{output}
        end{document}


        The result running in Cocalc is shown below:
        enter image description here



        By changing the value of q from 101 to something more, you'll get more points. SAGE is not part of the LaTeX distribution, so you would need to install it on your computer or, to avoid that, get a free Cocalc account. The documentation for SAGE is here and the documentation for sagetex is here on CTAN. The SAGE programming involves a mixture of SAGE commands mixed into Python code. If your work involves mathematics, then this is a very convenient package to learn.






        share|improve this answer












        Here's a sagetex solution using the computer algebra system, SAGE, to do the computations.



        documentclass[border=3pt]{standalone}
        usepackage{sagetex}
        usepackage{pgfplots}
        pgfplotsset{compat=1.15}
        begin{document}
        begin{sagesilent}
        xvalue =
        yvalue =
        for q in range(1,101):
        for p in range(1,q):
        xvalue += [(p*1.0/q*1.).n(digits=2)]
        yvalue += [(1/(q/gcd(p,q))).n(digits=2)]
        output = r""
        output += r"begin{tikzpicture}"
        output += r"begin{axis}["
        output += r"title={Thomae's function},"
        output += r"xlabel=$x$,"
        output += r"ylabel=$f(x)$,"
        output += r"]"
        output += r"addplot[only marks,mark options={mark size=.5pt}] coordinates {"
        for i in range(0,len(xvalue)):
        output += r"(%s, %s)"%(xvalue[i],yvalue[i])
        output += r"};"
        output += r"end{axis}"
        output += r"end{tikzpicture}"
        end{sagesilent}
        sagestr{output}
        end{document}


        The result running in Cocalc is shown below:
        enter image description here



        By changing the value of q from 101 to something more, you'll get more points. SAGE is not part of the LaTeX distribution, so you would need to install it on your computer or, to avoid that, get a free Cocalc account. The documentation for SAGE is here and the documentation for sagetex is here on CTAN. The SAGE programming involves a mixture of SAGE commands mixed into Python code. If your work involves mathematics, then this is a very convenient package to learn.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        DJP

        6,90921629




        6,90921629






















            up vote
            1
            down vote













            Welcome to TeX.SE! Here is a proposal. Of course, this is just a cartoon because I had to cut off q, as is done in your screen shot.



            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,1.1);
            foreach X in {1,...,7}
            {ifnumX=1
            draw (0.02,1/X) -- (-0.02,1/X) node[left]{$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 {5,4,...,2}
            {foreach Y in {1,...,Ymax}
            {draw (Y/X,0.02) -- (Y/X,-0.02) node[below,fill=white]{$frac{Y}{X}$};
            fill ({Y/X},1/X) circle(0.2pt);
            }
            }
            end{tikzpicture}
            end{document}


            enter image description here



            ADDENDUM: Without external programs, compiles in below 1sec on a 4 years old MacBook pro.



            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}
            {ifnumX=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}
            {ifnumX<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
            fill ({Y/X},1/X) circle(0.2pt);
            }
            }
            foreach X in {0,1,...,80}
            {fill (X/80,0) circle(0.2pt); }
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer























            • Your answer are excellent. Have you take the "virus" of the best users of LaTeX? :-):-). +1
              – Sebastiano
              4 hours ago










            • @Sebastiano Such a virus does not exist and I am certainly not the best user of LaTeX.
              – marmot
              4 hours ago










            • I hope you understand my line. I was joking; you're a very good, useless person to deny it.
              – Sebastiano
              4 hours ago










            • How would you suggest putting in dots on the x-axis? As shown in the screenshot
              – Miguel Cumming-Romo
              2 hours ago










            • @MiguelCumming-Romo Just add foreach X in {0,1,...,80} {fill (X/80,0) circle(0.2pt); } (you may replace 80 by some other number) as I did in my second example. To make the numbers irrational, you could shift the circles by a tiny irrational amount, but in the end none of the computer-generated numbers are irrational).
              – marmot
              2 hours ago

















            up vote
            1
            down vote













            Welcome to TeX.SE! Here is a proposal. Of course, this is just a cartoon because I had to cut off q, as is done in your screen shot.



            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,1.1);
            foreach X in {1,...,7}
            {ifnumX=1
            draw (0.02,1/X) -- (-0.02,1/X) node[left]{$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 {5,4,...,2}
            {foreach Y in {1,...,Ymax}
            {draw (Y/X,0.02) -- (Y/X,-0.02) node[below,fill=white]{$frac{Y}{X}$};
            fill ({Y/X},1/X) circle(0.2pt);
            }
            }
            end{tikzpicture}
            end{document}


            enter image description here



            ADDENDUM: Without external programs, compiles in below 1sec on a 4 years old MacBook pro.



            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}
            {ifnumX=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}
            {ifnumX<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
            fill ({Y/X},1/X) circle(0.2pt);
            }
            }
            foreach X in {0,1,...,80}
            {fill (X/80,0) circle(0.2pt); }
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer























            • Your answer are excellent. Have you take the "virus" of the best users of LaTeX? :-):-). +1
              – Sebastiano
              4 hours ago










            • @Sebastiano Such a virus does not exist and I am certainly not the best user of LaTeX.
              – marmot
              4 hours ago










            • I hope you understand my line. I was joking; you're a very good, useless person to deny it.
              – Sebastiano
              4 hours ago










            • How would you suggest putting in dots on the x-axis? As shown in the screenshot
              – Miguel Cumming-Romo
              2 hours ago










            • @MiguelCumming-Romo Just add foreach X in {0,1,...,80} {fill (X/80,0) circle(0.2pt); } (you may replace 80 by some other number) as I did in my second example. To make the numbers irrational, you could shift the circles by a tiny irrational amount, but in the end none of the computer-generated numbers are irrational).
              – marmot
              2 hours ago















            up vote
            1
            down vote










            up vote
            1
            down vote









            Welcome to TeX.SE! Here is a proposal. Of course, this is just a cartoon because I had to cut off q, as is done in your screen shot.



            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,1.1);
            foreach X in {1,...,7}
            {ifnumX=1
            draw (0.02,1/X) -- (-0.02,1/X) node[left]{$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 {5,4,...,2}
            {foreach Y in {1,...,Ymax}
            {draw (Y/X,0.02) -- (Y/X,-0.02) node[below,fill=white]{$frac{Y}{X}$};
            fill ({Y/X},1/X) circle(0.2pt);
            }
            }
            end{tikzpicture}
            end{document}


            enter image description here



            ADDENDUM: Without external programs, compiles in below 1sec on a 4 years old MacBook pro.



            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}
            {ifnumX=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}
            {ifnumX<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
            fill ({Y/X},1/X) circle(0.2pt);
            }
            }
            foreach X in {0,1,...,80}
            {fill (X/80,0) circle(0.2pt); }
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer














            Welcome to TeX.SE! Here is a proposal. Of course, this is just a cartoon because I had to cut off q, as is done in your screen shot.



            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,1.1);
            foreach X in {1,...,7}
            {ifnumX=1
            draw (0.02,1/X) -- (-0.02,1/X) node[left]{$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 {5,4,...,2}
            {foreach Y in {1,...,Ymax}
            {draw (Y/X,0.02) -- (Y/X,-0.02) node[below,fill=white]{$frac{Y}{X}$};
            fill ({Y/X},1/X) circle(0.2pt);
            }
            }
            end{tikzpicture}
            end{document}


            enter image description here



            ADDENDUM: Without external programs, compiles in below 1sec on a 4 years old MacBook pro.



            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}
            {ifnumX=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}
            {ifnumX<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
            fill ({Y/X},1/X) circle(0.2pt);
            }
            }
            foreach X in {0,1,...,80}
            {fill (X/80,0) circle(0.2pt); }
            end{tikzpicture}
            end{document}


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 hours ago

























            answered 4 hours ago









            marmot

            77.7k487166




            77.7k487166












            • Your answer are excellent. Have you take the "virus" of the best users of LaTeX? :-):-). +1
              – Sebastiano
              4 hours ago










            • @Sebastiano Such a virus does not exist and I am certainly not the best user of LaTeX.
              – marmot
              4 hours ago










            • I hope you understand my line. I was joking; you're a very good, useless person to deny it.
              – Sebastiano
              4 hours ago










            • How would you suggest putting in dots on the x-axis? As shown in the screenshot
              – Miguel Cumming-Romo
              2 hours ago










            • @MiguelCumming-Romo Just add foreach X in {0,1,...,80} {fill (X/80,0) circle(0.2pt); } (you may replace 80 by some other number) as I did in my second example. To make the numbers irrational, you could shift the circles by a tiny irrational amount, but in the end none of the computer-generated numbers are irrational).
              – marmot
              2 hours ago




















            • Your answer are excellent. Have you take the "virus" of the best users of LaTeX? :-):-). +1
              – Sebastiano
              4 hours ago










            • @Sebastiano Such a virus does not exist and I am certainly not the best user of LaTeX.
              – marmot
              4 hours ago










            • I hope you understand my line. I was joking; you're a very good, useless person to deny it.
              – Sebastiano
              4 hours ago










            • How would you suggest putting in dots on the x-axis? As shown in the screenshot
              – Miguel Cumming-Romo
              2 hours ago










            • @MiguelCumming-Romo Just add foreach X in {0,1,...,80} {fill (X/80,0) circle(0.2pt); } (you may replace 80 by some other number) as I did in my second example. To make the numbers irrational, you could shift the circles by a tiny irrational amount, but in the end none of the computer-generated numbers are irrational).
              – marmot
              2 hours ago


















            Your answer are excellent. Have you take the "virus" of the best users of LaTeX? :-):-). +1
            – Sebastiano
            4 hours ago




            Your answer are excellent. Have you take the "virus" of the best users of LaTeX? :-):-). +1
            – Sebastiano
            4 hours ago












            @Sebastiano Such a virus does not exist and I am certainly not the best user of LaTeX.
            – marmot
            4 hours ago




            @Sebastiano Such a virus does not exist and I am certainly not the best user of LaTeX.
            – marmot
            4 hours ago












            I hope you understand my line. I was joking; you're a very good, useless person to deny it.
            – Sebastiano
            4 hours ago




            I hope you understand my line. I was joking; you're a very good, useless person to deny it.
            – Sebastiano
            4 hours ago












            How would you suggest putting in dots on the x-axis? As shown in the screenshot
            – Miguel Cumming-Romo
            2 hours ago




            How would you suggest putting in dots on the x-axis? As shown in the screenshot
            – Miguel Cumming-Romo
            2 hours ago












            @MiguelCumming-Romo Just add foreach X in {0,1,...,80} {fill (X/80,0) circle(0.2pt); } (you may replace 80 by some other number) as I did in my second example. To make the numbers irrational, you could shift the circles by a tiny irrational amount, but in the end none of the computer-generated numbers are irrational).
            – marmot
            2 hours ago






            @MiguelCumming-Romo Just add foreach X in {0,1,...,80} {fill (X/80,0) circle(0.2pt); } (you may replace 80 by some other number) as I did in my second example. To make the numbers irrational, you could shift the circles by a tiny irrational amount, but in the end none of the computer-generated numbers are irrational).
            – marmot
            2 hours ago












            Miguel Cumming-Romo is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Miguel Cumming-Romo is a new contributor. Be nice, and check out our Code of Conduct.













            Miguel Cumming-Romo is a new contributor. Be nice, and check out our Code of Conduct.












            Miguel Cumming-Romo is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461603%2fgraphing-the-thomae-function%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Futebolista

            Jornalista