Plotting sine function on a diagram

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
1












I'm trying to plot a sine on a diagram (the wavefunction for a particle in a box). The intended result is:



enter image description here



However, the current situation is the following:



enter image description here



which is obtained from the following code:



% Diagram of a particle in 1D infinite potential well.
newcommandvandbarrier[1]%
node at (#1, 1) scriptsize $V = infty$;
node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


newcommandvabove[1]%
node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


begintikzpicture
fill[mygray] % mygray is custom defined color.
(0, 0) rectangle (2, 4)
(4, 0) rectangle (6, 4);

vandbarrier1.0
vandbarrier5.0
node[anchor = north] at (2, 0) scriptsize 0;
node[anchor = north] at (4, 0) scriptsize $L$;
node[anchor = north] at (6, 0) scriptsize $x$;

draw[<->] (0, 0) to (6, 0);
draw[->] (2, 0) to (2, 4);
draw[->] (4, 0) to (4, 4);

beginaxis[
%axis lines = none,
xmin = 0, xmax = 3,
ymin = 0, ymax =1,
]
addplot[domain = 0 : pi]sin(deg(x));
endaxis
endtikzpicture


What would be the easiest way to plot the above?



More, specifically: some help with the syntax and options of axis and addplot related to scaling and translation will be greatly appreciated.









share|improve this question
























    up vote
    6
    down vote

    favorite
    1












    I'm trying to plot a sine on a diagram (the wavefunction for a particle in a box). The intended result is:



    enter image description here



    However, the current situation is the following:



    enter image description here



    which is obtained from the following code:



    % Diagram of a particle in 1D infinite potential well.
    newcommandvandbarrier[1]%
    node at (#1, 1) scriptsize $V = infty$;
    node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


    newcommandvabove[1]%
    node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


    begintikzpicture
    fill[mygray] % mygray is custom defined color.
    (0, 0) rectangle (2, 4)
    (4, 0) rectangle (6, 4);

    vandbarrier1.0
    vandbarrier5.0
    node[anchor = north] at (2, 0) scriptsize 0;
    node[anchor = north] at (4, 0) scriptsize $L$;
    node[anchor = north] at (6, 0) scriptsize $x$;

    draw[<->] (0, 0) to (6, 0);
    draw[->] (2, 0) to (2, 4);
    draw[->] (4, 0) to (4, 4);

    beginaxis[
    %axis lines = none,
    xmin = 0, xmax = 3,
    ymin = 0, ymax =1,
    ]
    addplot[domain = 0 : pi]sin(deg(x));
    endaxis
    endtikzpicture


    What would be the easiest way to plot the above?



    More, specifically: some help with the syntax and options of axis and addplot related to scaling and translation will be greatly appreciated.









    share|improve this question






















      up vote
      6
      down vote

      favorite
      1









      up vote
      6
      down vote

      favorite
      1






      1





      I'm trying to plot a sine on a diagram (the wavefunction for a particle in a box). The intended result is:



      enter image description here



      However, the current situation is the following:



      enter image description here



      which is obtained from the following code:



      % Diagram of a particle in 1D infinite potential well.
      newcommandvandbarrier[1]%
      node at (#1, 1) scriptsize $V = infty$;
      node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


      newcommandvabove[1]%
      node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


      begintikzpicture
      fill[mygray] % mygray is custom defined color.
      (0, 0) rectangle (2, 4)
      (4, 0) rectangle (6, 4);

      vandbarrier1.0
      vandbarrier5.0
      node[anchor = north] at (2, 0) scriptsize 0;
      node[anchor = north] at (4, 0) scriptsize $L$;
      node[anchor = north] at (6, 0) scriptsize $x$;

      draw[<->] (0, 0) to (6, 0);
      draw[->] (2, 0) to (2, 4);
      draw[->] (4, 0) to (4, 4);

      beginaxis[
      %axis lines = none,
      xmin = 0, xmax = 3,
      ymin = 0, ymax =1,
      ]
      addplot[domain = 0 : pi]sin(deg(x));
      endaxis
      endtikzpicture


      What would be the easiest way to plot the above?



      More, specifically: some help with the syntax and options of axis and addplot related to scaling and translation will be greatly appreciated.









      share|improve this question












      I'm trying to plot a sine on a diagram (the wavefunction for a particle in a box). The intended result is:



      enter image description here



      However, the current situation is the following:



      enter image description here



      which is obtained from the following code:



      % Diagram of a particle in 1D infinite potential well.
      newcommandvandbarrier[1]%
      node at (#1, 1) scriptsize $V = infty$;
      node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


      newcommandvabove[1]%
      node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


      begintikzpicture
      fill[mygray] % mygray is custom defined color.
      (0, 0) rectangle (2, 4)
      (4, 0) rectangle (6, 4);

      vandbarrier1.0
      vandbarrier5.0
      node[anchor = north] at (2, 0) scriptsize 0;
      node[anchor = north] at (4, 0) scriptsize $L$;
      node[anchor = north] at (6, 0) scriptsize $x$;

      draw[<->] (0, 0) to (6, 0);
      draw[->] (2, 0) to (2, 4);
      draw[->] (4, 0) to (4, 4);

      beginaxis[
      %axis lines = none,
      xmin = 0, xmax = 3,
      ymin = 0, ymax =1,
      ]
      addplot[domain = 0 : pi]sin(deg(x));
      endaxis
      endtikzpicture


      What would be the easiest way to plot the above?



      More, specifically: some help with the syntax and options of axis and addplot related to scaling and translation will be greatly appreciated.











      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 28 at 15:11









      Ziezi

      18929




      18929




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          An option result like the first given image, and some of the nice summary of the code shown in other answers.



          RESULT:



          enter image description here



          MWE:



          documentclass[tikz,border=0pt]standalone
          usetikzlibraryarrows.meta
          usepackage[scaled]helvet
          usepackagestix
          begindocument
          definecolorbgHTMLFFE4C7
          pagecolorbg
          begintikzpicture[
          %Environment cfg
          >=Stealth[length=9pt,inset=0],
          font=sffamily
          ]
          defL3
          defDeep6
          defBorder0.8
          defh10.6
          defAmp1
          defSpread1.2

          fill[black!40]
          (0,0)
          |- ++(L,-Deep)
          |- ++(Border,Deep)
          |- ++(-L -2*Border,-Deep -Border)
          |- cycle;
          draw[line width=2pt, <->]
          (0,0)++(0,h1)
          node[anchor=south](T1)$mathsfinfty$
          |- ++(L,-Deep-h1) -- ++(0,Deep+h1)
          node[anchor=south](T2)$mathsfinfty$;
          draw[thick,<->]
          (0,-Deep+0.5) -- ++ (L,0) node[midway,fill=bg]L = L;

          foreach n in 1,2,3,4
          draw[very thick]
          (-0.4,-Deep+n*Spread) noden=n
          plot[
          variable=x,
          domain=0:L,
          smooth
          ](x,-Deep+n*Spread+0.4*sin(x*360*0.5*n/L));

          endtikzpicture
          enddocument





          share|improve this answer





























            up vote
            7
            down vote













            You do not necessarily need pgfplots for that. EDIT: Error fixed, big thanks to Max!



            documentclass[tikz,border=3.14mm]standalone
            begindocument
            definecolormygrayRGB127,127,127
            newcommandvandbarrier[1]%
            node at (#1, 1) scriptsize $V = infty$;
            node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


            newcommandvabove[1]%
            node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


            begintikzpicture
            fill[mygray] % mygray is custom defined color.
            (0, 0) rectangle (2, 4)
            (4, 0) rectangle (6, 4);

            vandbarrier1.0
            vandbarrier5.0
            node[anchor = north] at (2, 0) scriptsize 0;
            node[anchor = north] at (4, 0) scriptsize $L$;
            node[anchor = north] at (6, 0) scriptsize $x$;

            draw[latex-latex,very thick] (0, 0) to (6, 0);
            draw[-latex,very thick] (2, 0) to (2, 4);
            draw[-latex,very thick] (4, 0) to (4, 4);

            draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,1+0.4*cos(x*120));
            draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,2-0.4*sin(x*180));
            draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,3-0.4*cos(x*270));
            endtikzpicture
            enddocument


            enter image description here






            share|improve this answer






















            • @Max Good catch, thanks! +1 to your beautiful answer.
              – marmot
              Aug 28 at 16:13






            • 1




              No problem! You don't have to refer to me for such tiny details, the answer is still yours completely :)
              – Max
              Aug 28 at 16:14






            • 1




              @Max I thank you because I am really grateful. (One should not post answers while sitting in talks and having unstable internet .... ;-)
              – marmot
              Aug 28 at 17:09

















            up vote
            7
            down vote













            An alternative to @marmot's answer which uses the sin and cos path commands:



            enter image description here



            documentclass[tikz,margin=2mm]standalone

            definecolormygraygray0.4

            begindocument
            % Diagram of a particle in 1D infinite potential well.
            newcommandvandbarrier[1]%
            node at (#1, 1) scriptsize $V = infty$;
            node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


            newcommandvabove[1]%
            node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


            begintikzpicture
            fill[mygray] % mygray is custom defined color.
            (0, 0) rectangle (2, 4)
            (4, 0) rectangle (6, 4);

            vandbarrier1.0
            vandbarrier5.0
            node[anchor = north] at (2, 0) scriptsize 0;
            node[anchor = north] at (4, 0) scriptsize $L$;
            node[anchor = north] at (6, 0) scriptsize $x$;

            draw[<->] (0, 0) to (6, 0);
            draw[->] (2, 0) to (2, 4);
            draw[->] (4, 0) to (4, 4);

            pgfmathsetmacroamplitude0.5

            draw (2,1) sin ++(1,amplitude) cos ++(1,-amplitude);
            draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
            draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

            endtikzpicture
            enddocument


            Edit

            Just for fun, the same solution but now using a nested foreach to draw an arbitrary number of waves with increasing frequency:



            enter image description here



            documentclass[tikz,margin=2mm]standalone

            definecolormygraygray0.4

            begindocument
            % Diagram of a particle in 1D infinite potential well.
            newcommandvandbarrier[1]%
            node at (#1, 1) scriptsize $V = infty$;
            node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


            newcommandvabove[1]%
            node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


            begintikzpicture
            fill[mygray] % mygray is custom defined color.
            (0, 0) rectangle (2, 4)
            (4, 0) rectangle (6, 4);

            vandbarrier1.0
            vandbarrier5.0
            node[anchor = north] at (2, 0) scriptsize 0;
            node[anchor = north] at (4, 0) scriptsize $L$;
            node[anchor = north] at (6, 0) scriptsize $x$;

            draw[<->] (0, 0) to (6, 0);
            draw[->] (2, 0) to (2, 4);
            draw[->] (4, 0) to (4, 4);

            pgfmathsetmacroamplitude0.2

            foreach i in 1,...,8
            draw[blue] (2,(i-1)*amplitude*2.2+1.1*amplitude) foreach j [evaluate=j as dir using (-1)^j]in 1,...,i
            sin ++(1/i,-1*dir*amplitude) cos ++(1/i,dir*amplitude)
            ;

            %draw (2,1) sin ++(1/1,amplitude) cos ++(1/1,-amplitude);
            %draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
            %draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

            endtikzpicture
            enddocument





            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: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              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%2f448166%2fplotting-sine-function-on-a-diagram%23new-answer', 'question_page');

              );

              Post as a guest






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              7
              down vote



              accepted










              An option result like the first given image, and some of the nice summary of the code shown in other answers.



              RESULT:



              enter image description here



              MWE:



              documentclass[tikz,border=0pt]standalone
              usetikzlibraryarrows.meta
              usepackage[scaled]helvet
              usepackagestix
              begindocument
              definecolorbgHTMLFFE4C7
              pagecolorbg
              begintikzpicture[
              %Environment cfg
              >=Stealth[length=9pt,inset=0],
              font=sffamily
              ]
              defL3
              defDeep6
              defBorder0.8
              defh10.6
              defAmp1
              defSpread1.2

              fill[black!40]
              (0,0)
              |- ++(L,-Deep)
              |- ++(Border,Deep)
              |- ++(-L -2*Border,-Deep -Border)
              |- cycle;
              draw[line width=2pt, <->]
              (0,0)++(0,h1)
              node[anchor=south](T1)$mathsfinfty$
              |- ++(L,-Deep-h1) -- ++(0,Deep+h1)
              node[anchor=south](T2)$mathsfinfty$;
              draw[thick,<->]
              (0,-Deep+0.5) -- ++ (L,0) node[midway,fill=bg]L = L;

              foreach n in 1,2,3,4
              draw[very thick]
              (-0.4,-Deep+n*Spread) noden=n
              plot[
              variable=x,
              domain=0:L,
              smooth
              ](x,-Deep+n*Spread+0.4*sin(x*360*0.5*n/L));

              endtikzpicture
              enddocument





              share|improve this answer


























                up vote
                7
                down vote



                accepted










                An option result like the first given image, and some of the nice summary of the code shown in other answers.



                RESULT:



                enter image description here



                MWE:



                documentclass[tikz,border=0pt]standalone
                usetikzlibraryarrows.meta
                usepackage[scaled]helvet
                usepackagestix
                begindocument
                definecolorbgHTMLFFE4C7
                pagecolorbg
                begintikzpicture[
                %Environment cfg
                >=Stealth[length=9pt,inset=0],
                font=sffamily
                ]
                defL3
                defDeep6
                defBorder0.8
                defh10.6
                defAmp1
                defSpread1.2

                fill[black!40]
                (0,0)
                |- ++(L,-Deep)
                |- ++(Border,Deep)
                |- ++(-L -2*Border,-Deep -Border)
                |- cycle;
                draw[line width=2pt, <->]
                (0,0)++(0,h1)
                node[anchor=south](T1)$mathsfinfty$
                |- ++(L,-Deep-h1) -- ++(0,Deep+h1)
                node[anchor=south](T2)$mathsfinfty$;
                draw[thick,<->]
                (0,-Deep+0.5) -- ++ (L,0) node[midway,fill=bg]L = L;

                foreach n in 1,2,3,4
                draw[very thick]
                (-0.4,-Deep+n*Spread) noden=n
                plot[
                variable=x,
                domain=0:L,
                smooth
                ](x,-Deep+n*Spread+0.4*sin(x*360*0.5*n/L));

                endtikzpicture
                enddocument





                share|improve this answer
























                  up vote
                  7
                  down vote



                  accepted







                  up vote
                  7
                  down vote



                  accepted






                  An option result like the first given image, and some of the nice summary of the code shown in other answers.



                  RESULT:



                  enter image description here



                  MWE:



                  documentclass[tikz,border=0pt]standalone
                  usetikzlibraryarrows.meta
                  usepackage[scaled]helvet
                  usepackagestix
                  begindocument
                  definecolorbgHTMLFFE4C7
                  pagecolorbg
                  begintikzpicture[
                  %Environment cfg
                  >=Stealth[length=9pt,inset=0],
                  font=sffamily
                  ]
                  defL3
                  defDeep6
                  defBorder0.8
                  defh10.6
                  defAmp1
                  defSpread1.2

                  fill[black!40]
                  (0,0)
                  |- ++(L,-Deep)
                  |- ++(Border,Deep)
                  |- ++(-L -2*Border,-Deep -Border)
                  |- cycle;
                  draw[line width=2pt, <->]
                  (0,0)++(0,h1)
                  node[anchor=south](T1)$mathsfinfty$
                  |- ++(L,-Deep-h1) -- ++(0,Deep+h1)
                  node[anchor=south](T2)$mathsfinfty$;
                  draw[thick,<->]
                  (0,-Deep+0.5) -- ++ (L,0) node[midway,fill=bg]L = L;

                  foreach n in 1,2,3,4
                  draw[very thick]
                  (-0.4,-Deep+n*Spread) noden=n
                  plot[
                  variable=x,
                  domain=0:L,
                  smooth
                  ](x,-Deep+n*Spread+0.4*sin(x*360*0.5*n/L));

                  endtikzpicture
                  enddocument





                  share|improve this answer














                  An option result like the first given image, and some of the nice summary of the code shown in other answers.



                  RESULT:



                  enter image description here



                  MWE:



                  documentclass[tikz,border=0pt]standalone
                  usetikzlibraryarrows.meta
                  usepackage[scaled]helvet
                  usepackagestix
                  begindocument
                  definecolorbgHTMLFFE4C7
                  pagecolorbg
                  begintikzpicture[
                  %Environment cfg
                  >=Stealth[length=9pt,inset=0],
                  font=sffamily
                  ]
                  defL3
                  defDeep6
                  defBorder0.8
                  defh10.6
                  defAmp1
                  defSpread1.2

                  fill[black!40]
                  (0,0)
                  |- ++(L,-Deep)
                  |- ++(Border,Deep)
                  |- ++(-L -2*Border,-Deep -Border)
                  |- cycle;
                  draw[line width=2pt, <->]
                  (0,0)++(0,h1)
                  node[anchor=south](T1)$mathsfinfty$
                  |- ++(L,-Deep-h1) -- ++(0,Deep+h1)
                  node[anchor=south](T2)$mathsfinfty$;
                  draw[thick,<->]
                  (0,-Deep+0.5) -- ++ (L,0) node[midway,fill=bg]L = L;

                  foreach n in 1,2,3,4
                  draw[very thick]
                  (-0.4,-Deep+n*Spread) noden=n
                  plot[
                  variable=x,
                  domain=0:L,
                  smooth
                  ](x,-Deep+n*Spread+0.4*sin(x*360*0.5*n/L));

                  endtikzpicture
                  enddocument






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 28 at 23:14

























                  answered Aug 28 at 18:51









                  J Leon V.

                  6,331528




                  6,331528




















                      up vote
                      7
                      down vote













                      You do not necessarily need pgfplots for that. EDIT: Error fixed, big thanks to Max!



                      documentclass[tikz,border=3.14mm]standalone
                      begindocument
                      definecolormygrayRGB127,127,127
                      newcommandvandbarrier[1]%
                      node at (#1, 1) scriptsize $V = infty$;
                      node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                      newcommandvabove[1]%
                      node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                      begintikzpicture
                      fill[mygray] % mygray is custom defined color.
                      (0, 0) rectangle (2, 4)
                      (4, 0) rectangle (6, 4);

                      vandbarrier1.0
                      vandbarrier5.0
                      node[anchor = north] at (2, 0) scriptsize 0;
                      node[anchor = north] at (4, 0) scriptsize $L$;
                      node[anchor = north] at (6, 0) scriptsize $x$;

                      draw[latex-latex,very thick] (0, 0) to (6, 0);
                      draw[-latex,very thick] (2, 0) to (2, 4);
                      draw[-latex,very thick] (4, 0) to (4, 4);

                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,1+0.4*cos(x*120));
                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,2-0.4*sin(x*180));
                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,3-0.4*cos(x*270));
                      endtikzpicture
                      enddocument


                      enter image description here






                      share|improve this answer






















                      • @Max Good catch, thanks! +1 to your beautiful answer.
                        – marmot
                        Aug 28 at 16:13






                      • 1




                        No problem! You don't have to refer to me for such tiny details, the answer is still yours completely :)
                        – Max
                        Aug 28 at 16:14






                      • 1




                        @Max I thank you because I am really grateful. (One should not post answers while sitting in talks and having unstable internet .... ;-)
                        – marmot
                        Aug 28 at 17:09














                      up vote
                      7
                      down vote













                      You do not necessarily need pgfplots for that. EDIT: Error fixed, big thanks to Max!



                      documentclass[tikz,border=3.14mm]standalone
                      begindocument
                      definecolormygrayRGB127,127,127
                      newcommandvandbarrier[1]%
                      node at (#1, 1) scriptsize $V = infty$;
                      node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                      newcommandvabove[1]%
                      node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                      begintikzpicture
                      fill[mygray] % mygray is custom defined color.
                      (0, 0) rectangle (2, 4)
                      (4, 0) rectangle (6, 4);

                      vandbarrier1.0
                      vandbarrier5.0
                      node[anchor = north] at (2, 0) scriptsize 0;
                      node[anchor = north] at (4, 0) scriptsize $L$;
                      node[anchor = north] at (6, 0) scriptsize $x$;

                      draw[latex-latex,very thick] (0, 0) to (6, 0);
                      draw[-latex,very thick] (2, 0) to (2, 4);
                      draw[-latex,very thick] (4, 0) to (4, 4);

                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,1+0.4*cos(x*120));
                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,2-0.4*sin(x*180));
                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,3-0.4*cos(x*270));
                      endtikzpicture
                      enddocument


                      enter image description here






                      share|improve this answer






















                      • @Max Good catch, thanks! +1 to your beautiful answer.
                        – marmot
                        Aug 28 at 16:13






                      • 1




                        No problem! You don't have to refer to me for such tiny details, the answer is still yours completely :)
                        – Max
                        Aug 28 at 16:14






                      • 1




                        @Max I thank you because I am really grateful. (One should not post answers while sitting in talks and having unstable internet .... ;-)
                        – marmot
                        Aug 28 at 17:09












                      up vote
                      7
                      down vote










                      up vote
                      7
                      down vote









                      You do not necessarily need pgfplots for that. EDIT: Error fixed, big thanks to Max!



                      documentclass[tikz,border=3.14mm]standalone
                      begindocument
                      definecolormygrayRGB127,127,127
                      newcommandvandbarrier[1]%
                      node at (#1, 1) scriptsize $V = infty$;
                      node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                      newcommandvabove[1]%
                      node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                      begintikzpicture
                      fill[mygray] % mygray is custom defined color.
                      (0, 0) rectangle (2, 4)
                      (4, 0) rectangle (6, 4);

                      vandbarrier1.0
                      vandbarrier5.0
                      node[anchor = north] at (2, 0) scriptsize 0;
                      node[anchor = north] at (4, 0) scriptsize $L$;
                      node[anchor = north] at (6, 0) scriptsize $x$;

                      draw[latex-latex,very thick] (0, 0) to (6, 0);
                      draw[-latex,very thick] (2, 0) to (2, 4);
                      draw[-latex,very thick] (4, 0) to (4, 4);

                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,1+0.4*cos(x*120));
                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,2-0.4*sin(x*180));
                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,3-0.4*cos(x*270));
                      endtikzpicture
                      enddocument


                      enter image description here






                      share|improve this answer














                      You do not necessarily need pgfplots for that. EDIT: Error fixed, big thanks to Max!



                      documentclass[tikz,border=3.14mm]standalone
                      begindocument
                      definecolormygrayRGB127,127,127
                      newcommandvandbarrier[1]%
                      node at (#1, 1) scriptsize $V = infty$;
                      node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                      newcommandvabove[1]%
                      node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                      begintikzpicture
                      fill[mygray] % mygray is custom defined color.
                      (0, 0) rectangle (2, 4)
                      (4, 0) rectangle (6, 4);

                      vandbarrier1.0
                      vandbarrier5.0
                      node[anchor = north] at (2, 0) scriptsize 0;
                      node[anchor = north] at (4, 0) scriptsize $L$;
                      node[anchor = north] at (6, 0) scriptsize $x$;

                      draw[latex-latex,very thick] (0, 0) to (6, 0);
                      draw[-latex,very thick] (2, 0) to (2, 4);
                      draw[-latex,very thick] (4, 0) to (4, 4);

                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,1+0.4*cos(x*120));
                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,2-0.4*sin(x*180));
                      draw[blue,thick] plot[variable=x,domain=-1:1,smooth] (x+3,3-0.4*cos(x*270));
                      endtikzpicture
                      enddocument


                      enter image description here







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 28 at 16:12

























                      answered Aug 28 at 15:58









                      marmot

                      55.9k461122




                      55.9k461122











                      • @Max Good catch, thanks! +1 to your beautiful answer.
                        – marmot
                        Aug 28 at 16:13






                      • 1




                        No problem! You don't have to refer to me for such tiny details, the answer is still yours completely :)
                        – Max
                        Aug 28 at 16:14






                      • 1




                        @Max I thank you because I am really grateful. (One should not post answers while sitting in talks and having unstable internet .... ;-)
                        – marmot
                        Aug 28 at 17:09
















                      • @Max Good catch, thanks! +1 to your beautiful answer.
                        – marmot
                        Aug 28 at 16:13






                      • 1




                        No problem! You don't have to refer to me for such tiny details, the answer is still yours completely :)
                        – Max
                        Aug 28 at 16:14






                      • 1




                        @Max I thank you because I am really grateful. (One should not post answers while sitting in talks and having unstable internet .... ;-)
                        – marmot
                        Aug 28 at 17:09















                      @Max Good catch, thanks! +1 to your beautiful answer.
                      – marmot
                      Aug 28 at 16:13




                      @Max Good catch, thanks! +1 to your beautiful answer.
                      – marmot
                      Aug 28 at 16:13




                      1




                      1




                      No problem! You don't have to refer to me for such tiny details, the answer is still yours completely :)
                      – Max
                      Aug 28 at 16:14




                      No problem! You don't have to refer to me for such tiny details, the answer is still yours completely :)
                      – Max
                      Aug 28 at 16:14




                      1




                      1




                      @Max I thank you because I am really grateful. (One should not post answers while sitting in talks and having unstable internet .... ;-)
                      – marmot
                      Aug 28 at 17:09




                      @Max I thank you because I am really grateful. (One should not post answers while sitting in talks and having unstable internet .... ;-)
                      – marmot
                      Aug 28 at 17:09










                      up vote
                      7
                      down vote













                      An alternative to @marmot's answer which uses the sin and cos path commands:



                      enter image description here



                      documentclass[tikz,margin=2mm]standalone

                      definecolormygraygray0.4

                      begindocument
                      % Diagram of a particle in 1D infinite potential well.
                      newcommandvandbarrier[1]%
                      node at (#1, 1) scriptsize $V = infty$;
                      node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                      newcommandvabove[1]%
                      node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                      begintikzpicture
                      fill[mygray] % mygray is custom defined color.
                      (0, 0) rectangle (2, 4)
                      (4, 0) rectangle (6, 4);

                      vandbarrier1.0
                      vandbarrier5.0
                      node[anchor = north] at (2, 0) scriptsize 0;
                      node[anchor = north] at (4, 0) scriptsize $L$;
                      node[anchor = north] at (6, 0) scriptsize $x$;

                      draw[<->] (0, 0) to (6, 0);
                      draw[->] (2, 0) to (2, 4);
                      draw[->] (4, 0) to (4, 4);

                      pgfmathsetmacroamplitude0.5

                      draw (2,1) sin ++(1,amplitude) cos ++(1,-amplitude);
                      draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
                      draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

                      endtikzpicture
                      enddocument


                      Edit

                      Just for fun, the same solution but now using a nested foreach to draw an arbitrary number of waves with increasing frequency:



                      enter image description here



                      documentclass[tikz,margin=2mm]standalone

                      definecolormygraygray0.4

                      begindocument
                      % Diagram of a particle in 1D infinite potential well.
                      newcommandvandbarrier[1]%
                      node at (#1, 1) scriptsize $V = infty$;
                      node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                      newcommandvabove[1]%
                      node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                      begintikzpicture
                      fill[mygray] % mygray is custom defined color.
                      (0, 0) rectangle (2, 4)
                      (4, 0) rectangle (6, 4);

                      vandbarrier1.0
                      vandbarrier5.0
                      node[anchor = north] at (2, 0) scriptsize 0;
                      node[anchor = north] at (4, 0) scriptsize $L$;
                      node[anchor = north] at (6, 0) scriptsize $x$;

                      draw[<->] (0, 0) to (6, 0);
                      draw[->] (2, 0) to (2, 4);
                      draw[->] (4, 0) to (4, 4);

                      pgfmathsetmacroamplitude0.2

                      foreach i in 1,...,8
                      draw[blue] (2,(i-1)*amplitude*2.2+1.1*amplitude) foreach j [evaluate=j as dir using (-1)^j]in 1,...,i
                      sin ++(1/i,-1*dir*amplitude) cos ++(1/i,dir*amplitude)
                      ;

                      %draw (2,1) sin ++(1/1,amplitude) cos ++(1/1,-amplitude);
                      %draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
                      %draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

                      endtikzpicture
                      enddocument





                      share|improve this answer


























                        up vote
                        7
                        down vote













                        An alternative to @marmot's answer which uses the sin and cos path commands:



                        enter image description here



                        documentclass[tikz,margin=2mm]standalone

                        definecolormygraygray0.4

                        begindocument
                        % Diagram of a particle in 1D infinite potential well.
                        newcommandvandbarrier[1]%
                        node at (#1, 1) scriptsize $V = infty$;
                        node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                        newcommandvabove[1]%
                        node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                        begintikzpicture
                        fill[mygray] % mygray is custom defined color.
                        (0, 0) rectangle (2, 4)
                        (4, 0) rectangle (6, 4);

                        vandbarrier1.0
                        vandbarrier5.0
                        node[anchor = north] at (2, 0) scriptsize 0;
                        node[anchor = north] at (4, 0) scriptsize $L$;
                        node[anchor = north] at (6, 0) scriptsize $x$;

                        draw[<->] (0, 0) to (6, 0);
                        draw[->] (2, 0) to (2, 4);
                        draw[->] (4, 0) to (4, 4);

                        pgfmathsetmacroamplitude0.5

                        draw (2,1) sin ++(1,amplitude) cos ++(1,-amplitude);
                        draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
                        draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

                        endtikzpicture
                        enddocument


                        Edit

                        Just for fun, the same solution but now using a nested foreach to draw an arbitrary number of waves with increasing frequency:



                        enter image description here



                        documentclass[tikz,margin=2mm]standalone

                        definecolormygraygray0.4

                        begindocument
                        % Diagram of a particle in 1D infinite potential well.
                        newcommandvandbarrier[1]%
                        node at (#1, 1) scriptsize $V = infty$;
                        node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                        newcommandvabove[1]%
                        node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                        begintikzpicture
                        fill[mygray] % mygray is custom defined color.
                        (0, 0) rectangle (2, 4)
                        (4, 0) rectangle (6, 4);

                        vandbarrier1.0
                        vandbarrier5.0
                        node[anchor = north] at (2, 0) scriptsize 0;
                        node[anchor = north] at (4, 0) scriptsize $L$;
                        node[anchor = north] at (6, 0) scriptsize $x$;

                        draw[<->] (0, 0) to (6, 0);
                        draw[->] (2, 0) to (2, 4);
                        draw[->] (4, 0) to (4, 4);

                        pgfmathsetmacroamplitude0.2

                        foreach i in 1,...,8
                        draw[blue] (2,(i-1)*amplitude*2.2+1.1*amplitude) foreach j [evaluate=j as dir using (-1)^j]in 1,...,i
                        sin ++(1/i,-1*dir*amplitude) cos ++(1/i,dir*amplitude)
                        ;

                        %draw (2,1) sin ++(1/1,amplitude) cos ++(1/1,-amplitude);
                        %draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
                        %draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

                        endtikzpicture
                        enddocument





                        share|improve this answer
























                          up vote
                          7
                          down vote










                          up vote
                          7
                          down vote









                          An alternative to @marmot's answer which uses the sin and cos path commands:



                          enter image description here



                          documentclass[tikz,margin=2mm]standalone

                          definecolormygraygray0.4

                          begindocument
                          % Diagram of a particle in 1D infinite potential well.
                          newcommandvandbarrier[1]%
                          node at (#1, 1) scriptsize $V = infty$;
                          node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                          newcommandvabove[1]%
                          node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                          begintikzpicture
                          fill[mygray] % mygray is custom defined color.
                          (0, 0) rectangle (2, 4)
                          (4, 0) rectangle (6, 4);

                          vandbarrier1.0
                          vandbarrier5.0
                          node[anchor = north] at (2, 0) scriptsize 0;
                          node[anchor = north] at (4, 0) scriptsize $L$;
                          node[anchor = north] at (6, 0) scriptsize $x$;

                          draw[<->] (0, 0) to (6, 0);
                          draw[->] (2, 0) to (2, 4);
                          draw[->] (4, 0) to (4, 4);

                          pgfmathsetmacroamplitude0.5

                          draw (2,1) sin ++(1,amplitude) cos ++(1,-amplitude);
                          draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
                          draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

                          endtikzpicture
                          enddocument


                          Edit

                          Just for fun, the same solution but now using a nested foreach to draw an arbitrary number of waves with increasing frequency:



                          enter image description here



                          documentclass[tikz,margin=2mm]standalone

                          definecolormygraygray0.4

                          begindocument
                          % Diagram of a particle in 1D infinite potential well.
                          newcommandvandbarrier[1]%
                          node at (#1, 1) scriptsize $V = infty$;
                          node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                          newcommandvabove[1]%
                          node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                          begintikzpicture
                          fill[mygray] % mygray is custom defined color.
                          (0, 0) rectangle (2, 4)
                          (4, 0) rectangle (6, 4);

                          vandbarrier1.0
                          vandbarrier5.0
                          node[anchor = north] at (2, 0) scriptsize 0;
                          node[anchor = north] at (4, 0) scriptsize $L$;
                          node[anchor = north] at (6, 0) scriptsize $x$;

                          draw[<->] (0, 0) to (6, 0);
                          draw[->] (2, 0) to (2, 4);
                          draw[->] (4, 0) to (4, 4);

                          pgfmathsetmacroamplitude0.2

                          foreach i in 1,...,8
                          draw[blue] (2,(i-1)*amplitude*2.2+1.1*amplitude) foreach j [evaluate=j as dir using (-1)^j]in 1,...,i
                          sin ++(1/i,-1*dir*amplitude) cos ++(1/i,dir*amplitude)
                          ;

                          %draw (2,1) sin ++(1/1,amplitude) cos ++(1/1,-amplitude);
                          %draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
                          %draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

                          endtikzpicture
                          enddocument





                          share|improve this answer














                          An alternative to @marmot's answer which uses the sin and cos path commands:



                          enter image description here



                          documentclass[tikz,margin=2mm]standalone

                          definecolormygraygray0.4

                          begindocument
                          % Diagram of a particle in 1D infinite potential well.
                          newcommandvandbarrier[1]%
                          node at (#1, 1) scriptsize $V = infty$;
                          node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                          newcommandvabove[1]%
                          node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                          begintikzpicture
                          fill[mygray] % mygray is custom defined color.
                          (0, 0) rectangle (2, 4)
                          (4, 0) rectangle (6, 4);

                          vandbarrier1.0
                          vandbarrier5.0
                          node[anchor = north] at (2, 0) scriptsize 0;
                          node[anchor = north] at (4, 0) scriptsize $L$;
                          node[anchor = north] at (6, 0) scriptsize $x$;

                          draw[<->] (0, 0) to (6, 0);
                          draw[->] (2, 0) to (2, 4);
                          draw[->] (4, 0) to (4, 4);

                          pgfmathsetmacroamplitude0.5

                          draw (2,1) sin ++(1,amplitude) cos ++(1,-amplitude);
                          draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
                          draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

                          endtikzpicture
                          enddocument


                          Edit

                          Just for fun, the same solution but now using a nested foreach to draw an arbitrary number of waves with increasing frequency:



                          enter image description here



                          documentclass[tikz,margin=2mm]standalone

                          definecolormygraygray0.4

                          begindocument
                          % Diagram of a particle in 1D infinite potential well.
                          newcommandvandbarrier[1]%
                          node at (#1, 1) scriptsize $V = infty$;
                          node[scale = 0.5] at (#1, 0.5) textbf(Barrier);%


                          newcommandvabove[1]%
                          node[anchor = south] at (#1, 2) scriptsize $V = infty$;%


                          begintikzpicture
                          fill[mygray] % mygray is custom defined color.
                          (0, 0) rectangle (2, 4)
                          (4, 0) rectangle (6, 4);

                          vandbarrier1.0
                          vandbarrier5.0
                          node[anchor = north] at (2, 0) scriptsize 0;
                          node[anchor = north] at (4, 0) scriptsize $L$;
                          node[anchor = north] at (6, 0) scriptsize $x$;

                          draw[<->] (0, 0) to (6, 0);
                          draw[->] (2, 0) to (2, 4);
                          draw[->] (4, 0) to (4, 4);

                          pgfmathsetmacroamplitude0.2

                          foreach i in 1,...,8
                          draw[blue] (2,(i-1)*amplitude*2.2+1.1*amplitude) foreach j [evaluate=j as dir using (-1)^j]in 1,...,i
                          sin ++(1/i,-1*dir*amplitude) cos ++(1/i,dir*amplitude)
                          ;

                          %draw (2,1) sin ++(1/1,amplitude) cos ++(1/1,-amplitude);
                          %draw (2,2) sin ++(1/2,amplitude) cos ++(1/2,-amplitude) sin ++(1/2,-amplitude) cos ++(1/2,amplitude);
                          %draw (2,3) sin ++(1/3,amplitude) cos ++(1/3,-amplitude) sin ++(1/3,-amplitude) cos ++(1/3,amplitude) sin ++(1/3,amplitude) cos ++(1/3,-amplitude);

                          endtikzpicture
                          enddocument






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Aug 28 at 16:20

























                          answered Aug 28 at 16:01









                          Max

                          5,96811727




                          5,96811727



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f448166%2fplotting-sine-function-on-a-diagram%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery