绘制 3D 表面

绘制 3D 表面

我试图让我的情节尽可能接近这个:

页

代码:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, filecontents}


\begin{filecontents*}{filename.txt}


20  0.01 1.0261  
40  0.01 1.0622
60  0.01 1.0572
100 0.01 1.0276
150 0.01 1.0045
200 0.01 0.9945

20  0.02 1.0008
40  0.02 1.0230
60  0.02 1.0123
100 0.02 0.9889
150 0.02 0.9738
200 0.02 0.9641

20  0.03 0.9818
40  0.03 0.9894
60  0.03 0.9799
100 0.03 0.9636
150 0.03 0.9527
200 0.03 0.9487

20  0.05 0.9818
40  0.05 0.9503
60  0.05 0.9423
100 0.05 0.9362
150 0.05 0.9327
200 0.05 0.9319

20  0.09 0.9484
40  0.09 0.9187
60  0.09 0.9166
100 0.09 0.9152
150 0.09 0.9164
200 0.09 0.9183

20  0.10 0.9185
40  0.10 0.9151
60  0.10 0.9162
100 0.10 0.9149
150 0.10 0.9154
200 0.10 0.9167

20  0.20 0.9498
40  0.20 0.9490
60  0.20 0.9456
100 0.20 0.9464
150 0.20 0.9468
200 0.20 0.9480



\end{filecontents*}

%   colormap/winter,
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    font = \tiny,
    colormap/hot,
    view={50}{19},
    grid style={line width=.1pt, draw=gray!30},
%   ytick={0.01, 0.02, 0.03, 0.05, 0.09, 0.1, 0.2},
    scaled y ticks=true, yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=4}, 
%   xtick={20,40,60,100,150,200},
    scaled x ticks=true, yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=4}, 
    scaled z ticks=true, yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=4},
    xlabel={Ten}, ylabel={Rate $\lambda$}, zlabel={Percentage},
    grid=both]
    \addplot3[surf,point meta=z] file {filename.txt};
%   \addplot3[surf, point meta=explicit] table [z expr=0.2, meta index=2] {filename.txt};
    \end{axis}
    \end{tikzpicture}
\end{document}

输出: 在此处输入图片描述

有什么变化可以使我的情节看起来尽可能与黑色情节相似吗?背景也可以是白色。

答案1

这是对 @Faekynn 评论的回复。由于它对于评论来说太长了,因此这是一个社区 wiki 答案,我很乐意将其删除。

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{filecontents}
    \begin{filecontents*}{filename.txt}
        20  0.01 1.0261
        40  0.01 1.0622
        60  0.01 1.0572
        100 0.01 1.0276
        150 0.01 1.0045
        200 0.01 0.9945

        20  0.02 1.0008
        40  0.02 1.0230
        60  0.02 1.0123
        100 0.02 0.9889
        150 0.02 0.9738
        200 0.02 0.9641

        20  0.03 0.9818
        40  0.03 0.9894
        60  0.03 0.9799
        100 0.03 0.9636
        150 0.03 0.9527
        200 0.03 0.9487

        20  0.05 0.9818
        40  0.05 0.9503
        60  0.05 0.9423
        100 0.05 0.9362
        150 0.05 0.9327
        200 0.05 0.9319

        20  0.09 0.9484
        40  0.09 0.9187
        60  0.09 0.9166
        100 0.09 0.9152
        150 0.09 0.9164
        200 0.09 0.9183

        20  0.10 0.9185
        40  0.10 0.9151
        60  0.10 0.9162
        100 0.10 0.9149
        150 0.10 0.9154
        200 0.10 0.9167

        20  0.20 0.9498
        40  0.20 0.9490
        60  0.20 0.9456
        100 0.20 0.9464
        150 0.20 0.9468
        200 0.20 0.9480
    \end{filecontents*}
\usepackage{pgfplots}
    \usetikzlibrary{
        3d,
        calc,
        backgrounds,
    }
    \pgfplotsset{
        compat=1.16,
    }
    \colorlet{fgColor}{white}       % foreground color
    \colorlet{bgColor}{black}       % background color
\begin{document}
\begin{tikzpicture}[
    mygrid/.style={
        /utils/exec={%
            \pgfmathsetmacro{\nextx}{
                \pgfkeysvalueof{/tikz/mygrid/xmin}
                + 0.999 * \pgfkeysvalueof{/tikz/mygrid/xstep}
                * (\pgfkeysvalueof{/tikz/mygrid/xmax} - \pgfkeysvalueof{/tikz/mygrid/xmin})
            }
            \pgfmathsetmacro{\nexty}{
                \pgfkeysvalueof{/tikz/mygrid/ymin}
                + 0.999 * \pgfkeysvalueof{/tikz/mygrid/ystep}
                * (\pgfkeysvalueof{/tikz/mygrid/ymax} - \pgfkeysvalueof{/tikz/mygrid/ymin})
            }
        },
        insert path={
            foreach \XX in {
                \pgfkeysvalueof{/tikz/mygrid/xmin},
                \nextx,
                ...,
                \pgfkeysvalueof{/tikz/mygrid/xmax}
            } {
                (\XX,\pgfkeysvalueof{/tikz/mygrid/ymin}) --
                (\XX,\pgfkeysvalueof{/tikz/mygrid/ymax})
            }
            foreach \YY in {
                \pgfkeysvalueof{/tikz/mygrid/ymin},
                \nexty,
                ...,
                \pgfkeysvalueof{/tikz/mygrid/ymax}
            } {
                (\pgfkeysvalueof{/tikz/mygrid/xmin},\YY) --
                (\pgfkeysvalueof{/tikz/mygrid/xmax},\YY)
            }
        },
    },
    mygrid/.cd,
        xmin/.initial=0,
        xmax/.initial=1,
        xstep/.initial=0.1,
        ymin/.initial=0,
        ymax/.initial=1,
        ystep/.initial=0.1,
]
    \begin{axis}[
        view={70}{30},
        font=\tiny,
        colormap/hot,
        xmin=20,
        xmax=200,
        ymin=0,
        ymax=0.2,
        zmin=0.9,
        zmax=1.1,
        y dir=reverse,
        hide axis,
        %axis background/.style={fill=bgColor},
        clip=false,
    ]
        \begin{scope}[
            canvas is xy plane at z={
                \pgfkeysvalueof{/pgfplots/zmin}
                - 0.2 * (\pgfkeysvalueof{/pgfplots/zmax} - \pgfkeysvalueof{/pgfplots/zmin})
            },
        ]
            \path let
                \p1=($ (1,0,0) - (0,0,0) $),
                \n1={atan2(\y1,\x1)},
            in [
                top color=bgColor!60!fgColor,
                bottom color=bgColor,
                shading angle=\n1,
            ]
                (\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymin})
                rectangle
                (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax})
            ;
            \draw [
                fgColor,
                mygrid/xmin=\pgfkeysvalueof{/pgfplots/xmin},
                mygrid/xmax=\pgfkeysvalueof{/pgfplots/xmax},
                mygrid/ymin=\pgfkeysvalueof{/pgfplots/ymin},
                mygrid/ymax=\pgfkeysvalueof{/pgfplots/ymax},
                mygrid,
            ];
        \end{scope}

        \begin{scope}[
            canvas is yz plane at x={
                \pgfkeysvalueof{/pgfplots/xmin}
                - 0.2 * (\pgfkeysvalueof{/pgfplots/xmax} - \pgfkeysvalueof{/pgfplots/xmin})
            }
        ]
            \path let
                \p1=($ (1,0,0) - (0,0,0) $),
                \n1={atan2(\y1,\x1)},
            in [
                top color=bgColor!60!fgColor,
                bottom color=bgColor,
                shading angle=\n1,
            ]
                (\pgfkeysvalueof{/pgfplots/ymin},\pgfkeysvalueof{/pgfplots/zmin})
                rectangle
                (\pgfkeysvalueof{/pgfplots/ymax},\pgfkeysvalueof{/pgfplots/zmax})
            ;
            \draw [
                fgColor,
                mygrid/xmin=\pgfkeysvalueof{/pgfplots/ymin},
                mygrid/xmax=\pgfkeysvalueof{/pgfplots/ymax},
                mygrid/ymin=\pgfkeysvalueof{/pgfplots/zmin},
                mygrid/ymax=\pgfkeysvalueof{/pgfplots/zmax},
                mygrid,
            ];
        \end{scope}

        \begin{scope}[
            canvas is xz plane at y={
                \pgfkeysvalueof{/pgfplots/ymin}
                - 0.2 * (\pgfkeysvalueof{/pgfplots/ymax} - \pgfkeysvalueof{/pgfplots/ymin})
            },
        ]
            \path let
                \p1=($ (1,0,0) - (0,0,0) $),
                \n1={atan2(\y1,\x1)},
            in [
                top color=bgColor!60!fgColor,
                bottom color=bgColor,
                shading angle=\n1,
            ]
                (\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/zmin})
                rectangle
                (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/zmax})
            ;
            \draw [
                fgColor,
                mygrid/xmin=\pgfkeysvalueof{/pgfplots/xmin},
                mygrid/xmax=\pgfkeysvalueof{/pgfplots/xmax},
                mygrid/ymin=\pgfkeysvalueof{/pgfplots/zmin},
                mygrid/ymax=\pgfkeysvalueof{/pgfplots/zmax},
                mygrid,
            ];
        \end{scope}

        \addplot3 [surf,point meta=z] table {filename.txt};
    \end{axis}

    \begin{scope}[on background layer]
        \fill [
            bgColor,
        ]
            ([xshift=-5pt,yshift=-5pt] current bounding box.south west)
            rectangle
            ([xshift=+5pt,yshift=+5pt] current bounding box.north east)
        ;
    \end{scope}
\end{tikzpicture}
\end{document}

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

相关内容