# Heat equation: Squiggly lines

I am working on recreating an image of an heat equation as shown below

I have mostly been successful, however I am still not sure how to add the squiggly lines. Is there also an easier way to make sure the labels 1,0,and 1, are properly aligned? In the figure they have the same baseline, but in my graph they vary.

Any other improvements or ways to create the displayed image are appreciated as always

# Code

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}

\definecolor{UiT-main}{HTML}{003349}
\definecolor{UiT-blue}{HTML}{007396}
\definecolor{UiT-red}{HTML}{CB333B}

\begin{document}
\begin{tikzpicture}
\def\xmax{2}\def\ymax{2}
\shade[top color=white,bottom color=UiT-blue] (0,0) rectangle (\xmax,\ymax);
% Draw the border of the box and add labels
\draw [color=UiT-blue]
(0,0)         -- (\xmax,0)     node [pos=0.5,label=below:{\color{UiT-red}$u=g$}]{}
(\xmax,0)     -- (\xmax,\ymax) node [pos=0.5,label=right:{\color{UiT-red}$u=0$}]{}
(\xmax,\ymax) -- (0,\ymax)     node [pos=0.5,label=above:{\color{UiT-red}$u=0$}]{}
(0,\ymax)     -- (0,0)         node [pos=0.5,label= left:{\color{UiT-red}$u=0$}]{};
% Add the S in the centre
\path (0,\ymax)         -- (\xmax,0)     node [pos=0.5]{$S$};
% Draw the axis
\draw[thick,-stealth] (-1,0) -- (.5+\xmax,0) node[anchor= west] {$x$};
\draw[thick,-stealth] (0,-0.5) -- (0,.5+\ymax) node[anchor=south east] {$y$};
% Label the axis
\node[below left] (0,0) {$0$};
\node[label=left:{$1$}] (s2) at (0,\ymax) {};
\node[label=below:{$1$}] (s4) at (\xmax,0) {};
\end{tikzpicture}
\end{document}

• You can create squiggly lines with something like \draw (0,0) to[out=90, in=-90] (1,1);. – Skillmon Aug 12 at 12:38
• You may use pin and redefine pin on way as is described in 17.10.3 The Pin Option in TikZ & PGFmanula, pp 249 (v 3.1.4b) – Zarko Aug 12 at 12:48
• How is the first figure an "image of an heat equation"? – rafa11111 Aug 12 at 23:55
• @rafa11111 It is a very simple model where the temperature is g(x) at the x-axis then it decreases linearly with y until it reaches zero at y = 1. The plate is also insulated so the borders have a temperature of 0. That is the u = 0 ... parts =) – N3buchadnezzar Aug 13 at 8:36
• Of course, but I cannot see how it is relevant to the question, since it is about the squiggly lines. – rafa11111 Aug 13 at 11:52

Very similar to Skillmons answer (in that this uses in and out).

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,arrows.meta,bending}

\definecolor{UiT-main}{HTML}{003349}
\definecolor{UiT-blue}{HTML}{007396}
\definecolor{UiT-red}{HTML}{CB333B}

\begin{document}
\begin{tikzpicture}
\def\xmax{2}\def\ymax{2}
\shade[top color=white,bottom color=UiT-blue] (0,0) rectangle (\xmax,\ymax);
% Draw the border of the box and add labels
\draw [color=UiT-blue]
(0,0)         -- (\xmax,0)  coordinate[pos=0.6] (p1)   node[pos=0.5,UiT-red,below=1em](u1){$u=g$}
(\xmax,0)     -- (\xmax,\ymax) coordinate[pos=0.6] (p2)  node[pos=0.5,UiT-red,right=1em](u2){$u=0$}
(\xmax,\ymax) -- (0,\ymax) coordinate[pos=0.6] (p3)     node[pos=0.5,UiT-red,above=1em](u3){$u=0$}
(0,\ymax)     -- (0,0) coordinate[pos=0.6] (p4)          node[pos=0.5,UiT-red,left=1em](u4){$u=0$};
\foreach \X in {1,...,4}
{\draw[-{Stealth[bend]},UiT-red] (u\X) to[out=\X*90,in=\X*90-180] (p\X);}
% Add the S in the centre
\path (0,\ymax)         -- (\xmax,0)     node [pos=0.5]{$S$};
% Draw the axis
\draw[thick,-stealth] (-1,0) -- (.5+\xmax,0) node[anchor= west] {$x$};
\draw[thick,-stealth] (0,-0.5) -- (0,.5+\ymax) node[anchor=south east] {$y$};
% Label the axis
\path (0,0) node[below left]  {$0$}
(0,\ymax) node[left] {$1$} (\xmax,0) node[below] {$1$};
\end{tikzpicture}
\end{document}


• Fantastic answer as always Mormont! Any idea how to align the 0 with the two 1s in the picture? =) – N3buchadnezzar Aug 12 at 13:14
• @N3buchadnezzar I added something in which they are aligned. The issue is that you were using label in situations in which IMHO just nodes are the cleaner option. – user121799 Aug 12 at 13:19
• I agree that nodes are cleaner, why did I not think of that. Sorry for still being a novice when it comes to tikz. Thanks again for a wonderful answer – N3buchadnezzar Aug 12 at 13:22

Packing the lines into it with to and the out and in keys (quick and dirty).

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}

\definecolor{UiT-main}{HTML}{003349}
\definecolor{UiT-blue}{HTML}{007396}
\definecolor{UiT-red}{HTML}{CB333B}

\begin{document}
\begin{tikzpicture}
\def\xmax{2}\def\ymax{2}
\shade[top color=white,bottom color=UiT-blue] (0,0) rectangle (\xmax,\ymax);
% Draw the border of the box and add labels
\draw [color=UiT-blue]
(0,0)         -- (\xmax,0)     node
[pos=0.5,label=below:{\color{UiT-red}$u=g$}](b){}
(\xmax,0)     -- (\xmax,\ymax) node
[pos=0.5,label=right:{\color{UiT-red}$u=1$}](r){}
(\xmax,\ymax) -- (0,\ymax)     node
[pos=0.5,label=above:{\color{UiT-red}$u=2$}](t){}
(0,\ymax)     -- (0,0)         node [pos=0.5,label=
left:{\color{UiT-red}$u=3$}](l){};
% Add the S in the centre
\path (0,\ymax)         -- (\xmax,0)     node [pos=0.5]{$S$};
% Draw the axis
\draw[thick,-stealth] (-1,0) -- (.5+\xmax,0) node[anchor= west] {$x$};
\draw[thick,-stealth] (0,-0.5) -- (0,.5+\ymax) node[anchor=south east] {$y$};
% Label the axis
\node[below left] (0,0) {$0$};
\node[label=left:{$1$}] (s2) at (0,\ymax) {};
\node[label=below:{$1$}] (s4) at (\xmax,0) {};
%
\draw[<-,UiT-red] (b.center)++(.1,-0.01) to[out=-90,in=90] ++(-0.2,-0.25);
\draw[<-,UiT-red] (r.center)++(.01,+0.1) to[out=0,in=180] ++(0.25,-0.2);
\draw[<-,UiT-red] (t.center)++(.1,0.01) to[out=90,in=-90] ++(-0.2,0.25);
\draw[<-,UiT-red] (l.center)++(-.01,+0.1) to[out=180,in=0] ++(-0.25,-0.2);
\end{tikzpicture}
\end{document}