Draw different curves with different scales on TikZ











up vote
2
down vote

favorite












The following code



begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}


produces the picture:



enter image description here



As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?










share|improve this question


















  • 1




    This is what logarithmic plots are for.
    – marmot
    2 hours ago















up vote
2
down vote

favorite












The following code



begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}


produces the picture:



enter image description here



As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?










share|improve this question


















  • 1




    This is what logarithmic plots are for.
    – marmot
    2 hours ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











The following code



begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}


produces the picture:



enter image description here



As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?










share|improve this question













The following code



begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}


produces the picture:



enter image description here



As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?







tikz-pgf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









Mark

1806




1806








  • 1




    This is what logarithmic plots are for.
    – marmot
    2 hours ago














  • 1




    This is what logarithmic plots are for.
    – marmot
    2 hours ago








1




1




This is what logarithmic plots are for.
– marmot
2 hours ago




This is what logarithmic plots are for.
– marmot
2 hours ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.



documentclass[border=3mm]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.35,1.1)}}]
addplot[smooth,mark=*,blue]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
end{axis}

begin{axis}[name=plot2, axis y line*=right, axis x line=none,
xlabel=clusters ,colormap/blackwhite, legend style=
{at={(0.65,1.1)}}]
addplot[smooth,mark=square*,red]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer




























    up vote
    3
    down vote













    You could use a semilogyaxis.



    documentclass[tikz,border=3.14mm]{standalone}
    usepackage{pgfplots}
    pgfplotsset{compat=1.16}
    begin{document}
    begin{tikzpicture}[scale=0.9]
    begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
    {at={(0.95,0.6)}}]
    addlegendimage{empty legend}
    addlegendentry{Metrics}
    addplot+[smooth]
    coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
    addlegendentry{a}
    addplot+[smooth]
    coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
    (7,21.34288)};
    addlegendentry{b}
    end{semilogyaxis}
    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer





















    • Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
      – BambOo
      2 hours ago










    • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
      – marmot
      1 hour 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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464271%2fdraw-different-curves-with-different-scales-on-tikz%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
    2
    down vote



    accepted










    This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.



    documentclass[border=3mm]{standalone}
    usepackage{pgfplots}
    begin{document}
    begin{tikzpicture}[scale=0.9]
    begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
    {at={(0.35,1.1)}}]
    addplot[smooth,mark=*,blue]
    coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
    addlegendentry{a}
    end{axis}

    begin{axis}[name=plot2, axis y line*=right, axis x line=none,
    xlabel=clusters ,colormap/blackwhite, legend style=
    {at={(0.65,1.1)}}]
    addplot[smooth,mark=square*,red]
    coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
    (7,21.34288)};
    addlegendentry{b}
    end{axis}
    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer

























      up vote
      2
      down vote



      accepted










      This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.



      documentclass[border=3mm]{standalone}
      usepackage{pgfplots}
      begin{document}
      begin{tikzpicture}[scale=0.9]
      begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
      {at={(0.35,1.1)}}]
      addplot[smooth,mark=*,blue]
      coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
      addlegendentry{a}
      end{axis}

      begin{axis}[name=plot2, axis y line*=right, axis x line=none,
      xlabel=clusters ,colormap/blackwhite, legend style=
      {at={(0.65,1.1)}}]
      addplot[smooth,mark=square*,red]
      coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
      (7,21.34288)};
      addlegendentry{b}
      end{axis}
      end{tikzpicture}
      end{document}


      enter image description here






      share|improve this answer























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.



        documentclass[border=3mm]{standalone}
        usepackage{pgfplots}
        begin{document}
        begin{tikzpicture}[scale=0.9]
        begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
        {at={(0.35,1.1)}}]
        addplot[smooth,mark=*,blue]
        coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
        addlegendentry{a}
        end{axis}

        begin{axis}[name=plot2, axis y line*=right, axis x line=none,
        xlabel=clusters ,colormap/blackwhite, legend style=
        {at={(0.65,1.1)}}]
        addplot[smooth,mark=square*,red]
        coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
        (7,21.34288)};
        addlegendentry{b}
        end{axis}
        end{tikzpicture}
        end{document}


        enter image description here






        share|improve this answer












        This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.



        documentclass[border=3mm]{standalone}
        usepackage{pgfplots}
        begin{document}
        begin{tikzpicture}[scale=0.9]
        begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
        {at={(0.35,1.1)}}]
        addplot[smooth,mark=*,blue]
        coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
        addlegendentry{a}
        end{axis}

        begin{axis}[name=plot2, axis y line*=right, axis x line=none,
        xlabel=clusters ,colormap/blackwhite, legend style=
        {at={(0.65,1.1)}}]
        addplot[smooth,mark=square*,red]
        coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
        (7,21.34288)};
        addlegendentry{b}
        end{axis}
        end{tikzpicture}
        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        nidhin

        2,834926




        2,834926






















            up vote
            3
            down vote













            You could use a semilogyaxis.



            documentclass[tikz,border=3.14mm]{standalone}
            usepackage{pgfplots}
            pgfplotsset{compat=1.16}
            begin{document}
            begin{tikzpicture}[scale=0.9]
            begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
            {at={(0.95,0.6)}}]
            addlegendimage{empty legend}
            addlegendentry{Metrics}
            addplot+[smooth]
            coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
            addlegendentry{a}
            addplot+[smooth]
            coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
            (7,21.34288)};
            addlegendentry{b}
            end{semilogyaxis}
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer





















            • Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
              – BambOo
              2 hours ago










            • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
              – marmot
              1 hour ago















            up vote
            3
            down vote













            You could use a semilogyaxis.



            documentclass[tikz,border=3.14mm]{standalone}
            usepackage{pgfplots}
            pgfplotsset{compat=1.16}
            begin{document}
            begin{tikzpicture}[scale=0.9]
            begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
            {at={(0.95,0.6)}}]
            addlegendimage{empty legend}
            addlegendentry{Metrics}
            addplot+[smooth]
            coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
            addlegendentry{a}
            addplot+[smooth]
            coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
            (7,21.34288)};
            addlegendentry{b}
            end{semilogyaxis}
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer





















            • Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
              – BambOo
              2 hours ago










            • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
              – marmot
              1 hour ago













            up vote
            3
            down vote










            up vote
            3
            down vote









            You could use a semilogyaxis.



            documentclass[tikz,border=3.14mm]{standalone}
            usepackage{pgfplots}
            pgfplotsset{compat=1.16}
            begin{document}
            begin{tikzpicture}[scale=0.9]
            begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
            {at={(0.95,0.6)}}]
            addlegendimage{empty legend}
            addlegendentry{Metrics}
            addplot+[smooth]
            coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
            addlegendentry{a}
            addplot+[smooth]
            coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
            (7,21.34288)};
            addlegendentry{b}
            end{semilogyaxis}
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer












            You could use a semilogyaxis.



            documentclass[tikz,border=3.14mm]{standalone}
            usepackage{pgfplots}
            pgfplotsset{compat=1.16}
            begin{document}
            begin{tikzpicture}[scale=0.9]
            begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
            {at={(0.95,0.6)}}]
            addlegendimage{empty legend}
            addlegendentry{Metrics}
            addplot+[smooth]
            coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
            addlegendentry{a}
            addplot+[smooth]
            coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
            (7,21.34288)};
            addlegendentry{b}
            end{semilogyaxis}
            end{tikzpicture}
            end{document}


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            marmot

            82.3k492175




            82.3k492175












            • Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
              – BambOo
              2 hours ago










            • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
              – marmot
              1 hour ago


















            • Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
              – BambOo
              2 hours ago










            • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
              – marmot
              1 hour ago
















            Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
            – BambOo
            2 hours ago




            Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
            – BambOo
            2 hours ago












            @BambOo They are equivalent, see p. 41 of the pgfplots manual.
            – marmot
            1 hour ago




            @BambOo They are equivalent, see p. 41 of the pgfplots manual.
            – marmot
            1 hour ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464271%2fdraw-different-curves-with-different-scales-on-tikz%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

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            Alexandru Averescu

            Trompette piccolo