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:



enter image description here










share|improve this question


























    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:



    enter image description here










    share|improve this question
























      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:



      enter image description here










      share|improve this question













      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:



      enter image description here







      pgfplots






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Julia

      579516




      579516






















          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}


          enter image description here



          "EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)






          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',
            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%2f459664%2fproblem-with-loop-in-pgfplots%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            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}


            enter image description here



            "EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)






            share|improve this answer

























              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}


              enter image description here



              "EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)






              share|improve this answer























                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}


                enter image description here



                "EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)






                share|improve this answer












                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}


                enter image description here



                "EXPLANATION": When playing with pgfplots for a while, one comes across some standard tricks which one applies until one gets the desired result. ;-)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                marmot

                75k483159




                75k483159






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    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




















































































                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents