Plotting multiple functions in pgfplots












2















I have a function that I want to graph. However, there are 10 variations of it with 5 different constants each. I do not want to simply plug in a number 50 times. Is there an easier way to do this? Also, the graph comes out strangely. Is there an alternative to pgfplotsthat I use to generate an image and then just use includegraphics, preferably something with vector graphics so that it is of the highest quality. Thank you.



documentclass[letterpaper]{article}
usepackage{pgfplots} pgfplotsset{width=10cm,compat=1.16}

begin{document}


[ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


begin{figure}[htbp!]
centering
begin{tikzpicture}
begin{axis}[
legend pos=north east,
title = {},
xlabel = {time},
ylabel = {temperature},
xmin = 0, xmax = 15,
ymin = 0, ymax = 8,
xtick = {0, 5, 10, 15},
ytick = {0, 2, 4, 6, 8},
]

addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
addlegendentry{fitted function}

addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
addlegendentry{fitted function2}

end{axis}
end{tikzpicture}

end{figure}

end{document}









share|improve this question


















  • 1





    Yes, that's what declare function is for.

    – marmot
    3 hours ago











  • @marmot Thank you, but an example please? Also any suggestions for making the graph look better or other options? Edit. I spoke too soon. I think I can figure out the declare function. Though example would be nice in case I screw it up.

    – Ilyankor
    3 hours ago













  • Off-topic. There is no difference between ^prime and '; the latter makes the code easy to write.

    – manooooh
    1 hour ago
















2















I have a function that I want to graph. However, there are 10 variations of it with 5 different constants each. I do not want to simply plug in a number 50 times. Is there an easier way to do this? Also, the graph comes out strangely. Is there an alternative to pgfplotsthat I use to generate an image and then just use includegraphics, preferably something with vector graphics so that it is of the highest quality. Thank you.



documentclass[letterpaper]{article}
usepackage{pgfplots} pgfplotsset{width=10cm,compat=1.16}

begin{document}


[ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


begin{figure}[htbp!]
centering
begin{tikzpicture}
begin{axis}[
legend pos=north east,
title = {},
xlabel = {time},
ylabel = {temperature},
xmin = 0, xmax = 15,
ymin = 0, ymax = 8,
xtick = {0, 5, 10, 15},
ytick = {0, 2, 4, 6, 8},
]

addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
addlegendentry{fitted function}

addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
addlegendentry{fitted function2}

end{axis}
end{tikzpicture}

end{figure}

end{document}









share|improve this question


















  • 1





    Yes, that's what declare function is for.

    – marmot
    3 hours ago











  • @marmot Thank you, but an example please? Also any suggestions for making the graph look better or other options? Edit. I spoke too soon. I think I can figure out the declare function. Though example would be nice in case I screw it up.

    – Ilyankor
    3 hours ago













  • Off-topic. There is no difference between ^prime and '; the latter makes the code easy to write.

    – manooooh
    1 hour ago














2












2








2








I have a function that I want to graph. However, there are 10 variations of it with 5 different constants each. I do not want to simply plug in a number 50 times. Is there an easier way to do this? Also, the graph comes out strangely. Is there an alternative to pgfplotsthat I use to generate an image and then just use includegraphics, preferably something with vector graphics so that it is of the highest quality. Thank you.



documentclass[letterpaper]{article}
usepackage{pgfplots} pgfplotsset{width=10cm,compat=1.16}

begin{document}


[ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


begin{figure}[htbp!]
centering
begin{tikzpicture}
begin{axis}[
legend pos=north east,
title = {},
xlabel = {time},
ylabel = {temperature},
xmin = 0, xmax = 15,
ymin = 0, ymax = 8,
xtick = {0, 5, 10, 15},
ytick = {0, 2, 4, 6, 8},
]

addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
addlegendentry{fitted function}

addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
addlegendentry{fitted function2}

end{axis}
end{tikzpicture}

end{figure}

end{document}









share|improve this question














I have a function that I want to graph. However, there are 10 variations of it with 5 different constants each. I do not want to simply plug in a number 50 times. Is there an easier way to do this? Also, the graph comes out strangely. Is there an alternative to pgfplotsthat I use to generate an image and then just use includegraphics, preferably something with vector graphics so that it is of the highest quality. Thank you.



documentclass[letterpaper]{article}
usepackage{pgfplots} pgfplotsset{width=10cm,compat=1.16}

begin{document}


[ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


begin{figure}[htbp!]
centering
begin{tikzpicture}
begin{axis}[
legend pos=north east,
title = {},
xlabel = {time},
ylabel = {temperature},
xmin = 0, xmax = 15,
ymin = 0, ymax = 8,
xtick = {0, 5, 10, 15},
ytick = {0, 2, 4, 6, 8},
]

addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
addlegendentry{fitted function}

addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
addlegendentry{fitted function2}

end{axis}
end{tikzpicture}

end{figure}

end{document}






pgfplots graphics






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









IlyankorIlyankor

1138




1138








  • 1





    Yes, that's what declare function is for.

    – marmot
    3 hours ago











  • @marmot Thank you, but an example please? Also any suggestions for making the graph look better or other options? Edit. I spoke too soon. I think I can figure out the declare function. Though example would be nice in case I screw it up.

    – Ilyankor
    3 hours ago













  • Off-topic. There is no difference between ^prime and '; the latter makes the code easy to write.

    – manooooh
    1 hour ago














  • 1





    Yes, that's what declare function is for.

    – marmot
    3 hours ago











  • @marmot Thank you, but an example please? Also any suggestions for making the graph look better or other options? Edit. I spoke too soon. I think I can figure out the declare function. Though example would be nice in case I screw it up.

    – Ilyankor
    3 hours ago













  • Off-topic. There is no difference between ^prime and '; the latter makes the code easy to write.

    – manooooh
    1 hour ago








1




1





Yes, that's what declare function is for.

– marmot
3 hours ago





Yes, that's what declare function is for.

– marmot
3 hours ago













@marmot Thank you, but an example please? Also any suggestions for making the graph look better or other options? Edit. I spoke too soon. I think I can figure out the declare function. Though example would be nice in case I screw it up.

– Ilyankor
3 hours ago







@marmot Thank you, but an example please? Also any suggestions for making the graph look better or other options? Edit. I spoke too soon. I think I can figure out the declare function. Though example would be nice in case I screw it up.

– Ilyankor
3 hours ago















Off-topic. There is no difference between ^prime and '; the latter makes the code easy to write.

– manooooh
1 hour ago





Off-topic. There is no difference between ^prime and '; the latter makes the code easy to write.

– manooooh
1 hour ago










1 Answer
1






active

oldest

votes


















2














You can declare functions with the key declare function. (The TikZ library math has additional means to define functions, but this does not harmonize that well with pgfplots because pgfplots uses fpu.) Here is an example. This reproduces your plot with a declared function.



documentclass[letterpaper]{article}
usepackage{pgfplots}
pgfplotsset{width=10cm,compat=1.16}

begin{document}


[ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


begin{figure}[htbp!]
centering
begin{tikzpicture}[declare function={f(x,alpha,beta,gamma,lambda,phi)=%
(lambda*phi*( beta - alpha ))/(x*pow( 1 + pow( x/gamma,-phi),lambda)
*( 1 + pow(x/gamma,phi)));}]
begin{axis}[
legend pos=north east,
title = {},
xlabel = {time},
ylabel = {temperature},
xmin = 0, xmax = 15,
ymin = 0, ymax = 8,
xtick = {0, 5, 10, 15},
ytick = {0, 2, 4, 6, 8},
]

addplot[black, no marks, domain=0.01:15, smooth]
{f(x,23.3,42.2,3.15,1.86,3.38)};
%addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
addlegendentry{fitted function}

addplot[red, no marks, domain=0.01:15, smooth]
{f(x,23.8,43.6,1.38,12,3.01)};
%addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
addlegendentry{fitted function2}


end{axis}
end{tikzpicture}
end{figure}
end{document}


enter image description here






share|improve this answer

























    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%2f472176%2fplotting-multiple-functions-in-pgfplots%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You can declare functions with the key declare function. (The TikZ library math has additional means to define functions, but this does not harmonize that well with pgfplots because pgfplots uses fpu.) Here is an example. This reproduces your plot with a declared function.



    documentclass[letterpaper]{article}
    usepackage{pgfplots}
    pgfplotsset{width=10cm,compat=1.16}

    begin{document}


    [ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


    begin{figure}[htbp!]
    centering
    begin{tikzpicture}[declare function={f(x,alpha,beta,gamma,lambda,phi)=%
    (lambda*phi*( beta - alpha ))/(x*pow( 1 + pow( x/gamma,-phi),lambda)
    *( 1 + pow(x/gamma,phi)));}]
    begin{axis}[
    legend pos=north east,
    title = {},
    xlabel = {time},
    ylabel = {temperature},
    xmin = 0, xmax = 15,
    ymin = 0, ymax = 8,
    xtick = {0, 5, 10, 15},
    ytick = {0, 2, 4, 6, 8},
    ]

    addplot[black, no marks, domain=0.01:15, smooth]
    {f(x,23.3,42.2,3.15,1.86,3.38)};
    %addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
    addlegendentry{fitted function}

    addplot[red, no marks, domain=0.01:15, smooth]
    {f(x,23.8,43.6,1.38,12,3.01)};
    %addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
    addlegendentry{fitted function2}


    end{axis}
    end{tikzpicture}
    end{figure}
    end{document}


    enter image description here






    share|improve this answer






























      2














      You can declare functions with the key declare function. (The TikZ library math has additional means to define functions, but this does not harmonize that well with pgfplots because pgfplots uses fpu.) Here is an example. This reproduces your plot with a declared function.



      documentclass[letterpaper]{article}
      usepackage{pgfplots}
      pgfplotsset{width=10cm,compat=1.16}

      begin{document}


      [ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


      begin{figure}[htbp!]
      centering
      begin{tikzpicture}[declare function={f(x,alpha,beta,gamma,lambda,phi)=%
      (lambda*phi*( beta - alpha ))/(x*pow( 1 + pow( x/gamma,-phi),lambda)
      *( 1 + pow(x/gamma,phi)));}]
      begin{axis}[
      legend pos=north east,
      title = {},
      xlabel = {time},
      ylabel = {temperature},
      xmin = 0, xmax = 15,
      ymin = 0, ymax = 8,
      xtick = {0, 5, 10, 15},
      ytick = {0, 2, 4, 6, 8},
      ]

      addplot[black, no marks, domain=0.01:15, smooth]
      {f(x,23.3,42.2,3.15,1.86,3.38)};
      %addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
      addlegendentry{fitted function}

      addplot[red, no marks, domain=0.01:15, smooth]
      {f(x,23.8,43.6,1.38,12,3.01)};
      %addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
      addlegendentry{fitted function2}


      end{axis}
      end{tikzpicture}
      end{figure}
      end{document}


      enter image description here






      share|improve this answer




























        2












        2








        2







        You can declare functions with the key declare function. (The TikZ library math has additional means to define functions, but this does not harmonize that well with pgfplots because pgfplots uses fpu.) Here is an example. This reproduces your plot with a declared function.



        documentclass[letterpaper]{article}
        usepackage{pgfplots}
        pgfplotsset{width=10cm,compat=1.16}

        begin{document}


        [ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


        begin{figure}[htbp!]
        centering
        begin{tikzpicture}[declare function={f(x,alpha,beta,gamma,lambda,phi)=%
        (lambda*phi*( beta - alpha ))/(x*pow( 1 + pow( x/gamma,-phi),lambda)
        *( 1 + pow(x/gamma,phi)));}]
        begin{axis}[
        legend pos=north east,
        title = {},
        xlabel = {time},
        ylabel = {temperature},
        xmin = 0, xmax = 15,
        ymin = 0, ymax = 8,
        xtick = {0, 5, 10, 15},
        ytick = {0, 2, 4, 6, 8},
        ]

        addplot[black, no marks, domain=0.01:15, smooth]
        {f(x,23.3,42.2,3.15,1.86,3.38)};
        %addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
        addlegendentry{fitted function}

        addplot[red, no marks, domain=0.01:15, smooth]
        {f(x,23.8,43.6,1.38,12,3.01)};
        %addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
        addlegendentry{fitted function2}


        end{axis}
        end{tikzpicture}
        end{figure}
        end{document}


        enter image description here






        share|improve this answer















        You can declare functions with the key declare function. (The TikZ library math has additional means to define functions, but this does not harmonize that well with pgfplots because pgfplots uses fpu.) Here is an example. This reproduces your plot with a declared function.



        documentclass[letterpaper]{article}
        usepackage{pgfplots}
        pgfplotsset{width=10cm,compat=1.16}

        begin{document}


        [ y^{prime} ( t ) = frac{lambda phi ( beta - alpha )}{t left[ 1 + ( t/gamma)^{-phi} right]^lambda left[ 1 + (t/gamma)^{phi} right]} ]


        begin{figure}[htbp!]
        centering
        begin{tikzpicture}[declare function={f(x,alpha,beta,gamma,lambda,phi)=%
        (lambda*phi*( beta - alpha ))/(x*pow( 1 + pow( x/gamma,-phi),lambda)
        *( 1 + pow(x/gamma,phi)));}]
        begin{axis}[
        legend pos=north east,
        title = {},
        xlabel = {time},
        ylabel = {temperature},
        xmin = 0, xmax = 15,
        ymin = 0, ymax = 8,
        xtick = {0, 5, 10, 15},
        ytick = {0, 2, 4, 6, 8},
        ]

        addplot[black, no marks, domain=0.01:15, smooth]
        {f(x,23.3,42.2,3.15,1.86,3.38)};
        %addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
        addlegendentry{fitted function}

        addplot[red, no marks, domain=0.01:15, smooth]
        {f(x,23.8,43.6,1.38,12,3.01)};
        %addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
        addlegendentry{fitted function2}


        end{axis}
        end{tikzpicture}
        end{figure}
        end{document}


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 hours ago

























        answered 3 hours ago









        marmotmarmot

        95k4110210




        95k4110210






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f472176%2fplotting-multiple-functions-in-pgfplots%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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'