2

I am trying to draw a figure using TikZ. But I'm unable to finish it, also not able to give it a nice finishing.
This is what I am suppose to draw: enter image description here

This is my MWE:

\documentclass[border=1mm]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}

        \draw (-2,0) -- (-2,5);
        \draw (2,0) -- (2,5);
        \draw (-2,0) -- (2,0);
        \draw (-2,3) .. controls (-1.4,0.8) .. (2,3);
        \draw (-2,0.6) .. controls (1.4,2.3) .. (2,0.6);
        \end{tikzpicture}
\end{document}  

I'm looking for the code close to the above figure.

2
  • Why don't you simply plot two sine waves (appropriately scaled)? And could you highlight what exactly you are searching for (the lines in between, the curves, …)?
    – TeXnician
    Feb 26, 2019 at 12:58
  • @TeXnician Thanks it's a helpful idea. I actually need to draw something like this . Which is the closest I have drawn in the question. Edited my question as well
    – Shamina
    Feb 26, 2019 at 13:05

1 Answer 1

3

Like this?

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}
\begin{axis}[ width=7cm, height=5cm,    %aspect ratio
        xmin=-1, xmax=1, ymin=0, ymax=3.1,  %axis dimension
        samples=200,                                            %resolution
        axis line style={-}, 
        axis x line=bottom, x  axis line style={-|},
        xtick={-1,0,1},ymajorticks=false ,              %ticks
        xlabel=$x$,ylabel=$y$, every axis x label/.style={at={(ticklabel* cs:1.05)},anchor=west},every axis y label/.style={at={(ticklabel* cs:1.05)},anchor=south},    %axis labels
        ]


\addplot[color=black]{sin(deg(x)*3)+2};
\addplot[color=black]{sin(deg(x)*3)+1};
\draw[black!60, densely dashed,thick] (-.4, 1.06796091403) -- (.4, 1.93203908597);
\draw[black!60!red, densely dashed,thick] (-.4, 0.06796091403) -- (.4, 2.93203908597);

\end{axis}
\end{tikzpicture}
\end{document}

EDIT:

To get something that resembles the picture you linked, you can do this:

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ width=7cm, height=5cm,    %aspect ratio
        xmin=-1, xmax=1, ymin=0, ymax=3.1,  %axis dimension
        samples=200,                                            %resolution
        axis line style={-}, 
        axis x line=bottom, x  axis line style={-|},
        xtick={-1,0,1},ymajorticks=false ,              %ticks
        xlabel=$x$,ylabel=$y$       ]
\foreach \n in {1, ..., 35} 
    {
                \addplot[color=blue,thick]{sin(deg(x)*3.14159)+2.5+\n/20};
                \addplot[color=blue,thick]{sin(deg(x)*3.14159)+1.5-\n/20};
    }

            \addplot[color=blue,thick,domain=-.5:.5]{(sin(deg(x)*3.14159))*31/20+2};
            \addplot[color=blue,thick,domain=-.5:.5]{(sin(deg(x)*3.14159))*9/20+2};
\end{axis}
\end{tikzpicture}
\end{document}
4
  • Thanks! Yes very close. By that what i mean is: the end point of the curve should be at the same y-position(same vertical height) for both of the curves.
    – Shamina
    Feb 26, 2019 at 13:20
  • 1
    It's a sinus, so this will happen at pi and -pi, so if you just replace the 3 in the code with 3.14159... it should do the trick
    – sheß
    Feb 26, 2019 at 13:24
  • I see. In order to have axes labels as in the figure, we need to do?
    – Shamina
    Feb 26, 2019 at 13:35
  • 1
    Just remove all the stuff after every axis x label .... like i did in the second example
    – sheß
    Feb 26, 2019 at 13:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .