0

I'm trying to get my plot as close as this one:

p

CODE:

\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}

OUTPUT: enter image description here

Is there any change to make my plot look as similar as possible to the black one? The background can be white as well.

  • I assume this is possible by drawing several axis on after each other – crateane Aug 20 '19 at 18:51
  • NIce! But. haha how would you do that? – NaveganTeX Aug 20 '19 at 18:52
  • Here is an example with two polaraxis-environments, where the first one has a larger radius. you would need maybe three standard axis and shift them a bit around – crateane Aug 20 '19 at 18:57
  • 1
    Replace view={50}{19}, by view={70}{30},y dir=reverse,axis background/.style={fill=black},, this makes them more similar. – user194703 Aug 20 '19 at 19:11
  • 1
    I was thinking of something like \begin{axis}[yshift=-5cm view={50}{19}, xlabel={x}, ylabel={y}, zlabel={z},grid=both, hide z axis,xmin=0,xmax=200,ymin=0,ymax=0.2,zmin=0,zmax=1,]\end{axis}\begin{axis}[ view={50}{19}, xlabel={x}, ylabel={y}, zlabel={z},grid=both,hide x axis,hide y axis,]\addplot3[surf,point meta=z] file {filename.txt};\end{axis} but I do not know the pgfplots options well enough. Many of the axis lines remain, the options like hide x axis do not exactly what is needed here. – crateane Aug 20 '19 at 19:13
3

This is a reply to a comment by @Faekynn. Since it is too long for a comment, it is a community wiki answer, which I will be happy to delete.

% 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}

image showing the result of above code

  • Wow! It actually looks better than I expected! How do you add the labels? – NaveganTeX Aug 20 '19 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.