代码

代码

我的目标是获得类似下图的东西

在此处输入图片描述

我目前拥有的是

在此处输入图片描述

  • 我的主要问题是我发现很难TiKz与混合PGFplots,特别是我的图与文本相比太小,并且很难获得正确的坐标来放置文本。我确实尝试添加scale=2axis环境中,但这会弄乱绝对节点的位置。

  • 有没有更简单的方法来粗略地估计盆地的底部?现在我拟合了一个 8 次多项式,但它只是模糊地类似于形状,而且做起来很费劲。

代码

\documentclass[a4paper,11pt]{standalone}

\usepackage{pgfplots}

\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}

\begin{axis}[smooth,domain=0:1.65,unit vector ratio*=1 1 1,hide axis]
    \addplot[name path=A,very thick,black] (\x,{-3.15*\x^8 + 15.76*\x^7 - 22.74*\x^6 - 8.8*\x^5 + 54.34*\x^4 - 52.58*\x^3 + 18.88*\x^2 - 1.71*\x + 0.01});
  \addplot[name path=B,gray,opacity=0.4] (\x,{0.35});
  \addplot[gray,opacity=0.4] fill between[of=A and B];
  \node[] at (axis cs: 0,0.35) {Sea level};
  \draw[dashed] (axis cs: 0.4,0.2) -- (axis cs: 0.4,-0.1) (axis cs: 1.65,0.35) -- (axis cs: 1.65,-0.1);
\end{axis}

    \end{tikzpicture}

\end{document}

答案1

您无需尝试寻找函数,只需使用to[in=...,out=...]路径构造来绘制轮廓即可。只要 anin和后续的out相差 180 度,绘图就不会出现扭结。要回收路径,您可以使用insert path键来存储它。

\documentclass[tikz,11pt]{standalone}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\begin{tikzpicture}[scale=pi/2,thick,font=\sffamily\small,>={Latex[bend]},
    hills/.style={insert path={
     (0.2,1) to[out=0,in=240] (1.6,1.6) to[out=60,in=180] (2.3,2.3)
 to[out=0,in=135] (3.3,1.7) to[out=-45,in=180] (5,1) to[out=0,in=210] (9.5,3)}}]
 \begin{scope}
  \clip[hills] -| cycle;
  \fill[gray!40] (0.2,1) rectangle (9.5,2.6);
 \end{scope}
 \begin{scope}[thin]
  \clip [hills] -- (9.5,0) -- (0.2,0)-- cycle;
  \draw[dashed] (2.3,4) -- (2.3,0.3) (8.8,4) -- (8.8,0.3);
  \path (2.3,0.5) coordinate (L) -- (8.8,0.5) coordinate (R) node[midway](x){$x$};
  \foreach \X in {L,R} {\draw[->] (x) -- (\X);}
 \end{scope}
 \path (0.2,2.6) node[above right]{sea level};
 \draw[hills];
 \foreach \X in {1,...,5} {
    \draw[->] (1.7+1.25*\X,2.6) -- ++ (0,0.8)
    \ifnum\X=3
     node[above]{Evaporation}
    \fi; }
 \draw[->] (1.8,2.5) to[bend left=10] ++ (1.8,-0.2) node[right]{inflow};    
 \draw[->] (3.3,1.9)  node[right]{outflow}  to[bend right=15] ++ (-0.6,0.4);
 \draw[->] (7.2,2.5) -- ++ (0,-0.6) node[midway,left]{Precipitation};
 \draw[->] (7.8,2.5) -- ++ (0,-0.4);
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者使用颜色渐变。

\documentclass[tikz,11pt]{standalone}
\usepackage{tikzducks}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\begin{tikzpicture}[scale=pi/2,thick,font=\sffamily\small,>={Latex[bend]},
    hills/.style={insert path={
     (0.2,1) to[out=0,in=240] (1.6,1.6) to[out=60,in=180] (2.3,2.3)
 to[out=0,in=135] (3.3,1.7) to[out=-45,in=180] (5,1) to[out=0,in=210] (9.5,3)}}]
 \begin{scope}
  \clip[hills] -- ++ (0,0.5) -| cycle;
  \duck[shift={(4.4,2.4)},scale=0.3]
  \path[top color=blue!50,bottom color=blue,opacity=0.5] 
    (0.2,1) rectangle (9.5,2.6);
 \end{scope}
 \begin{scope}[thin]
  \clip [hills] -- (9.5,0) -- (0.2,0)-- cycle;
  \draw[dashed] (2.3,4) -- (2.3,0.3) (8.8,4) -- (8.8,0.3);
  \path (2.3,0.5) coordinate (L) -- (8.8,0.5) coordinate (R) node[midway](x){$x$};
  \foreach \X in {L,R} {\draw[->] (x) -- (\X);}
 \end{scope}
 \path (0.2,2.6) node[above right]{Sea level};
 \draw[hills];
 \foreach \X in {1,...,5} {
    \draw[->] (1.7+1.25*\X,2.6) -- ++ (0,0.8)
    \ifnum\X=3
     node[above]{Evaporation}
    \fi; }
 \draw[->] (1.8,2.5) to[bend left=10] ++ (1.8,-0.2) node[right]{Inflow};    
 \draw[->] (3.3,1.9)  node[anchor=172]{Outflow}  to[bend right=15] ++ (-0.6,0.4);
 \draw[->] (7.2,2.5) -- ++ (0,-0.6) node[midway,left]{Precipitation};
 \draw[->] (7.8,2.5) -- ++ (0,-0.4);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容