我正在努力重新创建热方程的图像,如下所示
我基本上成功了,但我仍然不确定如何添加波浪线。有没有更简单的方法来确保标签1
、0
和1
正确对齐?在图中它们具有相同的基线,但在我的图表中它们有所不同。
任何其他改进或创建显示图像的方法都会一如既往地受到赞赏
代码
\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 the box
\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}
答案1
与 Skillmons 的答案非常相似(因为使用了in
和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 the box
\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}
答案2
to
使用和out
键将线条打包到其中in
(快速而粗糙)。
\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 the box
\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}