Problem with loop in pgfplots
up vote
4
down vote
favorite
I am trying to loop through a parameter to produce shifted graphs in grouppplots, as in the following MWE, however the value of k
doesn't seem to be recognized in the argument of sin
, i.e. the black lines are not shifted. I inserted a red line with shift 0.25
manually for comparison. What did I do wrong?
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsforeachungrouped k in {0,0.25,0.5}{
nextgroupplot
addplot[domain=0:2] gnuplot {sin(2*pi*(x - k))} node[above,pos=0.5]{k};
addplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x - 0.25))} node[above,pos=0.5]{k};
}
end{groupplot}
end{tikzpicture}
end{document}
Output:
pgfplots
add a comment |
up vote
4
down vote
favorite
I am trying to loop through a parameter to produce shifted graphs in grouppplots, as in the following MWE, however the value of k
doesn't seem to be recognized in the argument of sin
, i.e. the black lines are not shifted. I inserted a red line with shift 0.25
manually for comparison. What did I do wrong?
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsforeachungrouped k in {0,0.25,0.5}{
nextgroupplot
addplot[domain=0:2] gnuplot {sin(2*pi*(x - k))} node[above,pos=0.5]{k};
addplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x - 0.25))} node[above,pos=0.5]{k};
}
end{groupplot}
end{tikzpicture}
end{document}
Output:
pgfplots
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I am trying to loop through a parameter to produce shifted graphs in grouppplots, as in the following MWE, however the value of k
doesn't seem to be recognized in the argument of sin
, i.e. the black lines are not shifted. I inserted a red line with shift 0.25
manually for comparison. What did I do wrong?
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsforeachungrouped k in {0,0.25,0.5}{
nextgroupplot
addplot[domain=0:2] gnuplot {sin(2*pi*(x - k))} node[above,pos=0.5]{k};
addplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x - 0.25))} node[above,pos=0.5]{k};
}
end{groupplot}
end{tikzpicture}
end{document}
Output:
pgfplots
I am trying to loop through a parameter to produce shifted graphs in grouppplots, as in the following MWE, however the value of k
doesn't seem to be recognized in the argument of sin
, i.e. the black lines are not shifted. I inserted a red line with shift 0.25
manually for comparison. What did I do wrong?
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsforeachungrouped k in {0,0.25,0.5}{
nextgroupplot
addplot[domain=0:2] gnuplot {sin(2*pi*(x - k))} node[above,pos=0.5]{k};
addplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x - 0.25))} node[above,pos=0.5]{k};
}
end{groupplot}
end{tikzpicture}
end{document}
Output:
pgfplots
pgfplots
asked 2 days ago
Julia
579516
579516
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Welcome to the expanding universe! (Yes, these expansion tricks can easily drive one close to madness. ;-))
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsinvokeforeach{0,0.25,0.5}{
nextgroupplot
edeftemp{noexpandaddplot[domain=0:2] gnuplot {sin(2*pi*(x - #1))}
node[above,pos=0.5]{#1};}
temp
edeftemp{noexpandaddplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x -
0.25))} node[above,pos=0.5]{#1};}
temp
}
end{groupplot}
end{tikzpicture}
end{document}
"EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Welcome to the expanding universe! (Yes, these expansion tricks can easily drive one close to madness. ;-))
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsinvokeforeach{0,0.25,0.5}{
nextgroupplot
edeftemp{noexpandaddplot[domain=0:2] gnuplot {sin(2*pi*(x - #1))}
node[above,pos=0.5]{#1};}
temp
edeftemp{noexpandaddplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x -
0.25))} node[above,pos=0.5]{#1};}
temp
}
end{groupplot}
end{tikzpicture}
end{document}
"EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)
add a comment |
up vote
2
down vote
accepted
Welcome to the expanding universe! (Yes, these expansion tricks can easily drive one close to madness. ;-))
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsinvokeforeach{0,0.25,0.5}{
nextgroupplot
edeftemp{noexpandaddplot[domain=0:2] gnuplot {sin(2*pi*(x - #1))}
node[above,pos=0.5]{#1};}
temp
edeftemp{noexpandaddplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x -
0.25))} node[above,pos=0.5]{#1};}
temp
}
end{groupplot}
end{tikzpicture}
end{document}
"EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Welcome to the expanding universe! (Yes, these expansion tricks can easily drive one close to madness. ;-))
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsinvokeforeach{0,0.25,0.5}{
nextgroupplot
edeftemp{noexpandaddplot[domain=0:2] gnuplot {sin(2*pi*(x - #1))}
node[above,pos=0.5]{#1};}
temp
edeftemp{noexpandaddplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x -
0.25))} node[above,pos=0.5]{#1};}
temp
}
end{groupplot}
end{tikzpicture}
end{document}
"EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)
Welcome to the expanding universe! (Yes, these expansion tricks can easily drive one close to madness. ;-))
documentclass{standalone}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
begin{document}
begin{tikzpicture}
begin{groupplot}[group style={group size=1 by 3},width=textwidth,height=4cm,xmin=0,xmax=2,samples=200]
pgfplotsinvokeforeach{0,0.25,0.5}{
nextgroupplot
edeftemp{noexpandaddplot[domain=0:2] gnuplot {sin(2*pi*(x - #1))}
node[above,pos=0.5]{#1};}
temp
edeftemp{noexpandaddplot[domain=0:2,red,dashed] gnuplot {sin(2*pi*(x -
0.25))} node[above,pos=0.5]{#1};}
temp
}
end{groupplot}
end{tikzpicture}
end{document}
"EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)
answered 2 days ago
marmot
75k483159
75k483159
add a comment |
add a comment |
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459664%2fproblem-with-loop-in-pgfplots%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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