4

Does anyone have an idea for how I can draw the following figure using TikZ? enter image description here

Many thanks.

2 Answers2

12

For such tasks hobby seems to be an appropriate tool.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=0.3*\x+2*cos(20*\x-40);
    r=0.5;},>=stealth]
 \def\lsty{6.2,7.2,6.8,5.6,5.0,4.8,4.8}
 \def\lstB{}
 \def\x{0}
 \loop
  \pgfmathsetmacro{\y}{0.2*{\lsty}[\x]+f(\x)}
  \ifnum\x=0
   \edef\lstA{(-1,{f(0)-0.25*{\lsty}[0]})}
   \edef\lstP{(\x,\y)}
  \else
   \edef\lstP{\lstP,(\x,\y)}
  \fi
  \edef\lstA{\lstA (\x,\y)}
  \pgfmathsetmacro{\y}{\y-r*{\lsty}[\x]}
  \edef\lstB{(\x,\y) \lstB}
  \edef\x{\the\numexpr\x+1}
 \ifnum\x<7\repeat
 %
 \draw[closed hobby,fill=blue!20] plot coordinates {\lstA (\x,{\y+0.5*r*{\lsty}[\x-1]}) \lstB} ;
%  %
 \foreach \x [count=\n from 0] in \lstP
 {\pgfmathsetmacro{\y}{{\lsty}[\n]}
 \path \x coordinate (t-\n) -- node(n-\n){$\y$} ++ (0,{-r*\y}) coordinate (b-\n)
   (n-\n) edge[->] (t-\n) edge[->] (b-\n);
 }
\end{tikzpicture}
\end{document}

enter image description here

Or with foreach. (I stole a function Dim from https://tex.stackexchange.com/a/570712 because I could not find anything else that works, for some reason the built-in but undocumented function dim that has been suggested elsewhere does not yield good results. Maybe there is a better way.)

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{hobby}
\makeatletter
\pgfmathdeclarefunction{Dim}{1}{% from https://tex.stackexchange.com/a/570712
  \begingroup%
    \pgfmath@count=0\relax
    \edef\pgfutil@tmpb{#1}%
    \pgfutil@for\pgfutil@tmpa:={\pgfutil@tmpb}\do{%
      \advance\pgfmath@count by1\relax}%
    \edef\pgfmathresult{\the\pgfmath@count}% 
    \pgfmath@smuggleone\pgfmathresult% 
  \endgroup}  
\makeatother
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=0.3*\x+2*cos(20*\x-40);},>=stealth]
 \def\lsty{6.2,7.2,6.8,5.6,5.0,4.8,4.8}
 \pgfmathtruncatemacro{\mydim}{Dim("\lsty")}
 \foreach \y [count=\x from 0] in \lsty
 {
 \path (\x,{0.2*\y+f(\x)}) coordinate (t-\x)
  -- coordinate (n-\x)
  (\x,{-0.3*\y+f(\x)}) coordinate[alias=b-\x] 
  (t-\the\numexpr2*\mydim-1-\x);
 }
 \draw[closed hobby,fill=blue!20]  plot[samples
    at={0,...,\the\numexpr2*\mydim-1}] (t-\x);
 \path foreach \y [count=\x from 0]in \lsty 
 {(n-\x) node{$\y$} edge[->] (t-\x) edge[->] (b-\x)};
\end{tikzpicture}
\end{document}
2

Just my attempt.

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{arrows, hobby, calc}
\begin{document}
\begin{tikzpicture}
\foreach \dy [count=\i] in {6.2,7.2,6.8,5.6,5.0,4.8,4.8} {
   \coordinate (A\i) at (2*\i,{3*sin(0.4*(\i-1) r)}); 
   \coordinate  (B\i) at ($ (A\i)+(0,\dy) $);
}
\draw[very thick, fill=blue!20] plot[closed hobby] coordinates  {(0,3)(A1)(A2)(A3)(A4)(A5)(A6)(A7)(16,4)(B7)(B6)(B5)(B4)(B3)(B2)(B1)};
\foreach \dy [count=\i] in {6.2,7.2,6.8,5.6,5.0,4.8,4.8}
   \draw[very thick,<->,>=stealth] (A\i) -- node[fill=blue!20]{\dy} (B\i);
\end{tikzpicture}
\end{document}

Shape with vertical arrows