Draw different curves with different scales on TikZ












5














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


















  • 2




    This is what logarithmic plots are for.
    – marmot
    Dec 11 at 8:39
















5














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


















  • 2




    This is what logarithmic plots are for.
    – marmot
    Dec 11 at 8:39














5












5








5







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 Dec 11 at 8:32









Mark

1956




1956








  • 2




    This is what logarithmic plots are for.
    – marmot
    Dec 11 at 8:39














  • 2




    This is what logarithmic plots are for.
    – marmot
    Dec 11 at 8:39








2




2




This is what logarithmic plots are for.
– marmot
Dec 11 at 8:39




This is what logarithmic plots are for.
– marmot
Dec 11 at 8:39










2 Answers
2






active

oldest

votes


















4














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]
pgfplotsset{every axis legend/.style={
anchor= west,
draw=none,}
}

begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
y tick label style={blue},
legend style= {at={(0.78,0.55)}},
]
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,
y tick label style={red},
legend style= {at={(0.78,0.45)}},
]
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































    5














    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
      Dec 11 at 9:00










    • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
      – marmot
      Dec 11 at 9:01











    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',
    autoActivateHeartbeat: false,
    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









    4














    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]
    pgfplotsset{every axis legend/.style={
    anchor= west,
    draw=none,}
    }

    begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
    y tick label style={blue},
    legend style= {at={(0.78,0.55)}},
    ]
    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,
    y tick label style={red},
    legend style= {at={(0.78,0.45)}},
    ]
    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




























      4














      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]
      pgfplotsset{every axis legend/.style={
      anchor= west,
      draw=none,}
      }

      begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
      y tick label style={blue},
      legend style= {at={(0.78,0.55)}},
      ]
      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,
      y tick label style={red},
      legend style= {at={(0.78,0.45)}},
      ]
      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


























        4












        4








        4






        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]
        pgfplotsset{every axis legend/.style={
        anchor= west,
        draw=none,}
        }

        begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
        y tick label style={blue},
        legend style= {at={(0.78,0.55)}},
        ]
        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,
        y tick label style={red},
        legend style= {at={(0.78,0.45)}},
        ]
        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]
        pgfplotsset{every axis legend/.style={
        anchor= west,
        draw=none,}
        }

        begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
        y tick label style={blue},
        legend style= {at={(0.78,0.55)}},
        ]
        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,
        y tick label style={red},
        legend style= {at={(0.78,0.45)}},
        ]
        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








        edited Dec 11 at 12:43

























        answered Dec 11 at 9:07









        nidhin

        3,344927




        3,344927























            5














            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
              Dec 11 at 9:00










            • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
              – marmot
              Dec 11 at 9:01
















            5














            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
              Dec 11 at 9:00










            • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
              – marmot
              Dec 11 at 9:01














            5












            5








            5






            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 Dec 11 at 8:45









            marmot

            85.1k495179




            85.1k495179












            • Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
              – BambOo
              Dec 11 at 9:00










            • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
              – marmot
              Dec 11 at 9:01


















            • Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
              – BambOo
              Dec 11 at 9:00










            • @BambOo They are equivalent, see p. 41 of the pgfplots manual.
              – marmot
              Dec 11 at 9:01
















            Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
            – BambOo
            Dec 11 at 9:00




            Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ?
            – BambOo
            Dec 11 at 9:00












            @BambOo They are equivalent, see p. 41 of the pgfplots manual.
            – marmot
            Dec 11 at 9:01




            @BambOo They are equivalent, see p. 41 of the pgfplots manual.
            – marmot
            Dec 11 at 9:01


















            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

            Probability when a professor distributes a quiz and homework assignment to a class of n students.

            Aardman Animations

            Are they similar matrix