不使用 pngplots 填充参数曲线

不使用 pngplots 填充参数曲线

我正在尝试填充两个参数曲线的面积,如下所示:

在此处输入图片描述

这是我迄今为止失败的尝试:

在此处输入图片描述

我理想情况下希望不是使用pngplots。我知道它pngplots随库一起提供fillbetween(例如用例这里),但我想知道有没有办法做到这一点而不使用它。我一直在浏览文档Tikz,但找不到任何东西。如果没有 ,就没有好的方法fillbetween,那就这样吧。

以下是用于制作图片的 MWE:

\documentclass[crop, tikz]{standalone}

\definecolor{axiscol}{HTML}{bebebe} % light gray
\definecolor{fillcol}{HTML}{ffbf00} % amber
\definecolor{arrowcol}{HTML}{cc5500} % orange amber

\begin{document}

\begin{tikzpicture}[domain = -2:2, variable = \y, smooth]

    \draw[axiscol, latex-latex] (-3.5,0) -- (3.5,0) node[right, axiscol] {\(x\)};
    \draw[axiscol, latex-latex] (0,-3.5) -- (0,3.5) node[above, axiscol] {\(y\)};

    \draw[color = arrowcol, very thick] plot ({sin(\y r) + 2}, \y) plot ({exp(-0.5*\y) - 1.65}, \y);
    \fill[color = fillcol] plot ({sin(\y r) + 2}, \y) plot ({exp(-0.5*\y) - 1.65}, \y);

\end{tikzpicture}

\end{document}

答案1

您可以添加第二个\path,基本上使用图来定义封闭的形状,这样一旦您设置了正确的域,就可以使用它来填充该区域。

输出

在此处输入图片描述

代码

\documentclass[crop, tikz]{standalone}

\definecolor{axiscol}{HTML}{bebebe} % light gray
\definecolor{fillcol}{HTML}{ffbf00} % amber
\definecolor{arrowcol}{HTML}{cc5500} % orange amber

\begin{document}

\begin{tikzpicture}[domain = -2:2, variable = \y, smooth]

    \draw[axiscol, latex-latex] (-3.5,0) -- (3.5,0) node[right, axiscol] {\(x\)};
    \draw[axiscol, latex-latex] (0,-3.5) -- (0,3.5) node[above, axiscol] {\(y\)};

    \path[fill=fillcol] 
        plot [smooth,samples=100,domain=-2:2] ({sin(\y r) + 2}, \y)  -- 
        plot [smooth,samples=100,domain=2:-2] ({exp(-0.5*\y) - 1.65}, \y); 
    \draw[color = arrowcol, very thick] 
        plot ({sin(\y r) + 2}, \y) 
        plot ({exp(-0.5*\y) - 1.65}, \y);  
\end{tikzpicture}
\end{document}

相关内容