在 Latex 中绘制图片

在 Latex 中绘制图片

我怎样才能在 Latex 中绘制这样的图片? enter image description here

答案1

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{arrows.meta}
\tikzset{axis/.style={draw=gray, ->, thin}, axis scale/.style={x=4cm/405, y=1cm},
  shorten/.style={shorten >=#1, shorten <=#1}, shorten/.default=1mm}
\begin{document}
\begin{tikzpicture}[line join=round, line cap=round, >=Triangle, font=\small]
\draw [axis, axis scale] (-420, 0) -- (420, 0) node [at end, below] {$x$};
\draw [axis, axis scale] (0, -0.5) -- (0, 2)   node [at end, left]  {$y$};
\draw [thick, axis scale] 
  plot [domain=-420:420, samples=100, smooth] (\x, 0.5*cos \x);
\draw [axis scale, shift=(90:1)] 
  plot [domain=-420:420, samples=60, smooth, ycomb] (\x, 0.5*cos \x - 1);
\node at (0, 1) [above, fill=white] {The applied external pressure};
\node [align=center, anchor=north west] (free-surface-label)
  at (-4, -1) {The initial free surface \\ $y=\eta(x,0)=0$};
\node [align=center, anchor=north east] (subsequent-surface-label)
  at (4, -1) {The subsequent free surface \\ $y=\eta(x,t)=0$};
\draw [->, shorten] ([axis scale]-380, 0) -- (free-surface-label);
\draw [->, shorten] ([axis scale]380, 0.5*cos 380) -- (subsequent-surface-label);
\tikzset{shift=(270:4)}
\draw [thick, axis scale] 
  plot [domain=-420:420, samples=200] (\x, {abs(\x) >= 180 ? 0 : 1.5*(0.81 - (\x/200)^2)});
\node at (0,0) [align=center] {$y=-h + \varepsilon(k, x)$ \\ The non-horizontal bottom};
\draw [axis scale, <->, shorten] (-420,0) -- (-420,4) node [midway, left] {$h$};
\end{tikzpicture}
\end{document} 

enter image description here

答案2

这是带有 的代码。您必须使用 MiKTeX、TeX Live 或 MacTeX 的开关pstricks启动编译器。--enable-write18-shell-escape

\documentclass[pdf, svgnames, x11names, border=3pt]{standalone}
\usepackage[usestackEOL]{stackengine}
\usepackage{pstricks-add, auto-pst-pdf}

\begin{document}

\psset{algebraic, plotpoints=200, arrowinset=0.12, linejoin=1}
\small
\begin{pspicture}(-8.5,-8)(7.5,4)
    \uput[dl](0,0){$ O $}
    \pscustom[fillstyle=solid, fillstyle=vlines, hatchangle=0, hatchwidth=0.4pt, hatchsep=4pt, linestyle=none]{
        \psplot{-7.5}{7.5}{cos(x)}\psline(7.5,1.8)(-7.5,1.8)}
    \psplot[linecolor=IndianRed, linewidth=1.2pt, plotstyle=curve, plotpoints=200]{-7.5}{7.5}{cos(x)}\closepath
    \psaxes[ticks=none, labels=none]{->}(0,0)(-7.5,-1)(7.5,4)[$x$,-110][$y$, -160]
    \uput[dl](0,0){$ O $}
    \pnodes(-7,0){H}(-7,-5.5){K}(-6,0){Ini}(7,0.75){Sub}
    \psset{nodesep=3pt}
    \ncline[arrows=<->]{H}{K}\ncput*{$ h $}
    \psline(-7.5,-5.5)(-3,-5.5)\psparabola(-3,-5.5)(0,-3)\psline(3,-5.5)(7.5,-5.5)
    \rput(0,-5.5){\Centerstack{$ y = -h + kε(x)$\\ The non-horizontal bottom}}
    \rput(0,2.5){\psframebox[linestyle = none, fillstyle=solid, fillcolor=white]{The applied external pressure}}
    \psnode(-4.2,-2.2){IFS}{\Centerstack{The initial free surface\\ $ y = η(x, 0) = 0$}}
    \ncline[arrows=->]{Ini}{IFS}
    \psnode(4.2,-2.2){SFS}{\Centerstack{The subsequent free surface\\ $ y = η(x, t)$}}
    \ncline[arrows=->]{Sub}{SFS}
\end{pspicture}

\end{document}

enter image description here

相关内容