在三维图上绘制实线

在三维图上绘制实线

我正在尝试绘制一条沿 3D 图形移动的线来表示积分区域。

在此处输入图片描述

因此,底部的黑线代表积分区域的截止点。我希望有一条沿着函数表面移动的线的轨迹。这是 MWE:

\PassOptionsToPackage{usenames,dvipsnames,table,x11names}{xcolor}
\documentclass[a4paper, 12pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps,fillbetween}

\begin{document}

\begin{tikzpicture}

\begin{axis}[
zmax=15,
zmin=0,
view = {45}{45},
grid=minor,
colormap={mycol}{color=(Tan), color=(Tan)},
xlabel = $s$,
ylabel = $h$,
zlabel = {$f(s,h)$},
ticks = none,
]

\addplot3[
surf,
samples=30,
domain=0:1.5,
opacity=0.5,
]
{12*exp(-(4*x+3*y))};

\draw[black, thick] (0,0,0) -- (1.5,1.5,0);

\addplot3 [name path = xline, draw = none, domain=0:1.5] (x,0,0);
\addplot3 [name path = xcurve, domain=0:1.5, y domain = 0:0, draw = none] 
    (x, 0, {12*exp(-(4*x))});
\addplot [color = Tan, opacity = 0.5, draw = none]
  fill between[of = xcurve and xline];

\addplot3[
mesh,
draw=Bittersweet,
samples=30,
domain=0:1.5,
opacity = 0.75
]
{12*exp(-(4*x+3*y))};

% Attempt 1
%\addplot3 [domain=0:1.5, black, thick, samples=30] (x,x,{12*exp(-(4*x+3*y))});

%Attempt 2
%\addplot3 [domain=0:1.5, black, thick, samples=30] (x,x,{12*exp(-(7*x))});

\end{axis}
\end{tikzpicture}

结尾处注释掉的两行,我称之为“尝试 1”和“尝试 2”,就是我尝试这样做的两次。以下是每次尝试的结果:

尝试 1

在此处输入图片描述

第二次尝试

在此处输入图片描述

尝试 1 很乱,但尝试 2 非常接近我想要的,但它在函数的起点和终点之间画了一条线。有什么建议可以解决这个问题吗?

答案1

你已经走在正确的道路上。通过增加samples y=1第二次尝试,你可以实现你想要的目标。

(除此之外,我对您的代码做了一些小的优化。有关详细信息,请参阅代码中的注释。)

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
        compat=1.16,
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        zmax=15,
        zmin=0,
        view={45}{45},
        grid=minor,
        colormap={mycol}{color=(Tan), color=(Tan)},
        xlabel=$s$,
        ylabel=$h$,
        zlabel={$f(s,h)$},
        ticks=none,
        % (moved common options here)
        domain=0:1.5,
        samples=30,
    ]

        \addplot3[
            surf,
            opacity=0.5,
            % removed one `\addplot' by adding the next line
            faceted color=Bittersweet,
        ] {12*exp(-(4*x+3*y))};

        \draw [black, thick] (0,0,0) -- (1.5,1.5,0);

        \addplot3 [
            name path=xline,
            draw=none,
        ] (x,0,0);
        \addplot3 [
            name path=xcurve,
            % replaced this ...
%            y domain=0:0,
            % by ...
            samples y=1,
            draw=none,
        ] (x,0,{12*exp(-(4*x))});
        \addplot [color=Tan, opacity=0.5]
            fill between [of=xcurve and xline];


        % Attempt 2
        \addplot3 [
            black,
            thick,
            samples y=1,        % <-- added
        ] (x,x,{12*exp(-7*x)});

    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容