用颜色表示第四维的三维曲面图

用颜色表示第四维的三维曲面图

我有一个函数,其中输出“w”取决于三个变量,如下所示:

w = x^2 * (3 + 2*x)(1+x*y)(1+x*z)/(1+x^2)

x、y 和 z 可以取从 0 到 2 的任意值

我希望能够绘制一个 3D 表面,其中 x、y、z 为坐标,w 由上述方程求值,其值表示为表面颜色。因此,实际上它将提供 4 维信息。下面是我正在尝试构建但目前无法做到的代码的 MWE。

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}[
    declare function = {
        q(\x) = \x - 1;
        Z(\x,\y) = \x^2 + \y^2 + q(\x);
    }
    ]
    \begin{axis}
    \addplot3 [surf] {Z(x,y)};
    \end{axis}
    \end{tikzpicture}
\end{document}

答案1

所以你的意思就是这样的?

然后只需声明您的w函数并将其用作point meta表达式即可。通过调整point meta minpoint meta max值,您可以稍微玩一下“4D 效果”。

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.3,
    }
\begin{document}
    \begin{tikzpicture}[
        declare function = {
            q(\x) = \x - 1;
            Z(\x,\y) = \x^2 + \y^2 + q(\x);
%            % in your provided function the multiplication signs are missing
%            % at the given positions indicated by "v" in the next line
%            %                              v         v
%            w(\x,\y,\z) = \x^2 * (3 + 2*\x) (1+\x*\y) (1+\x*\z)/(1+\x^2);
%            % it seems that is is interpreted as the following line, which
%            % gives the same result
%            w(\x,\y,\z) = (1+\x*\z)/(1+\x^2);
            % adding the multiplication signs yield the "right"/intended result
            w(\x,\y,\z) = \x^2 * (3 + 2*\x)*(1+\x*\y)*(1+\x*\z)/(1+\x^2);
        }
    ]
        \begin{axis}[
            colormap/viridis,
            colorbar,
            % adjust these values to your needs or comment/delete them,
            % to automatically set them to the calculated min and max values
            point meta min=-1e4,
            point meta max=+1e4,
        ]
            \addplot3 [
                surf,
                point meta={w(x,y,z)}
            ] {Z(x,y)};
        \end{axis}
    \end{tikzpicture}
\end{document}

结果图

相关内容