Plotting multiple functions in pgfplots
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 pgfplots
that 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
add a comment |
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 pgfplots
that 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
1
Yes, that's whatdeclare function
is for.
– marmot
Jan 28 at 4:52
@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 thedeclare function
. Though example would be nice in case I screw it up.
– Ilyankor
Jan 28 at 4:54
Off-topic. There is no difference between^prime
and'
; the latter makes the code easy to write.
– manooooh
Jan 28 at 6:50
add a comment |
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 pgfplots
that 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
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 pgfplots
that 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
pgfplots graphics
asked Jan 28 at 4:45
IlyankorIlyankor
1138
1138
1
Yes, that's whatdeclare function
is for.
– marmot
Jan 28 at 4:52
@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 thedeclare function
. Though example would be nice in case I screw it up.
– Ilyankor
Jan 28 at 4:54
Off-topic. There is no difference between^prime
and'
; the latter makes the code easy to write.
– manooooh
Jan 28 at 6:50
add a comment |
1
Yes, that's whatdeclare function
is for.
– marmot
Jan 28 at 4:52
@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 thedeclare function
. Though example would be nice in case I screw it up.
– Ilyankor
Jan 28 at 4:54
Off-topic. There is no difference between^prime
and'
; the latter makes the code easy to write.
– manooooh
Jan 28 at 6:50
1
1
Yes, that's what
declare function
is for.– marmot
Jan 28 at 4:52
Yes, that's what
declare function
is for.– marmot
Jan 28 at 4:52
@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
Jan 28 at 4:54
@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
Jan 28 at 4:54
Off-topic. There is no difference between
^prime
and '
; the latter makes the code easy to write.– manooooh
Jan 28 at 6:50
Off-topic. There is no difference between
^prime
and '
; the latter makes the code easy to write.– manooooh
Jan 28 at 6:50
add a comment |
1 Answer
1
active
oldest
votes
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}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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}
add a comment |
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}
add a comment |
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}
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}
edited Jan 28 at 5:56
answered Jan 28 at 5:04
marmotmarmot
112k5143268
112k5143268
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Yes, that's what
declare function
is for.– marmot
Jan 28 at 4:52
@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
Jan 28 at 4:54
Off-topic. There is no difference between
^prime
and'
; the latter makes the code easy to write.– manooooh
Jan 28 at 6:50