1

Starting from the example http://pgfplots.net/tikz/examples/contour-and-surface/, I would like to make projection of a surface, defined by a table. The X and Y projections work OK, but the Z projection appears at the top, rather than at the bottom. I guess it is because of the log scale. What do I wrong? The picture below illustrates my problem. (I know, the picture is not attractive and not reasonable, but I wanted to reduce the size for an MWE)

enter image description here

Edition: I also attach an image generated from my full data set. The Y projection is about what I expected. The X projection is funny: just vertical lines, without connection. It looks a bad projection is made: the prohcetd to the Y axis broken lines are projected to the X plane, without any connection. I expected broken lines like the ones in the Y projection. I have no idea what the Z projection is. It looks like it makes a few niveaus around the highest values, and this is all.

enter image description here

I have two differences from the sample: one is the logarithmic scale and the other is the tabular data. I changed the Z scale to linear and setzmin=1e-4, zmax=.1. The result is the third figure. Based on this, I guess that the Y projection is OK, the X projection uses wrong projection direction and Z projection cannot do anything with this wide-range data.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{verbatim}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
%http://pgfplots.net/tikz/examples/contour-and-surface/
\pgfplotstableset{%
    col sep=semicolon,
    x index=0,
    y index=1,
    z index=2,
    header=false
}%

\begin{filecontents*}{data/XYZ.csv}
   2016; 1;      32.7e-9
   2016;10;      1560e-9
   2016;20;      9811e-9
   2016;25;      5204e-9

   2015; 1;   199e-9
   2015;10;   438e-9
   2015;20;   674e-9
   2015;25;  1718e-9

   2014; 1;    199e-9
   2014;10;   2446e-9
   2014;20;   1893e-9
   2014;25;   2670e-9

   1994; 1;   76957E-9
   1994;10;54545455e-9
   1994;20; 1390462e-9
   1994;25; 1440795e-9

   1993; 1;  1167453e-9
   1993;10;  7484185e-9
   1993;20;  7484185e-9
   1993;25;  8876163e-9
\end{filecontents*}


\begin{document}
\begin{tikzpicture}
\pgfplotsset{
    every axis/.append style={
        scale only axis,
        width=\textwidth,
       height=\textwidth,
        xtick={1995,2000,2005,2010,2015},
        ytick={1,10,20,25},
        ztick={1e-8,1e-6,1e-4,1e-2,1e-0}
    },
    /tikz/every picture/.append style={
        trim axis left,
        trim axis right,
    }
    }
   \begin{axis}
      [ %nodes near coords={(\coordindex)},
    domain=1980:2020,
    domain y=1:40,
      footnotesize,
      title={Hillside},
            /pgf/number format/.cd,
        use comma,
        1000 sep={},
        xlabel=Year,
        ylabel=position,
        xmin=1980, xmax=2020,% x scale
        ymin=1, ymax=40, % y scale
        zmin=1e-12, zmax=1, % z scale
        xlabel=Year,
        zmode = log,
        grid=major,
        grid style={dotted},
        colormap/jet,
        zmode=log,
      ]

\addplot3
[surf]
    table {data/XYZ.csv};

% This is the Z (bottom) projection
    \addplot3[
        contour gnuplot={
            % cdata should not be affected by z filter:
            output point meta=rawz,
            number=15,
            labels=false,
        },
        z filter/.code=\def\pgfmathresult{1E-4},
    ]
    table {data/XYZ.csv};
% This is the X projection
    \addplot3[
        domain=1980:2020,
        domain y=1:30,
        % we want 1d (!) individually colored mesh segments:
        mesh, patch type=line,
        x filter/.code=\def\pgfmathresult{1980},
    ] 
    table {data/XYZ.csv};

%% This is the Y projection
    \addplot3[
        % we want 1d (!) individually colored mesh segments:
        mesh, patch type=line,
        y filter/.code=\def\pgfmathresult{40},
    ] 
    table {data/XYZ.csv};
\end{axis}
\end{tikzpicture}

\end{document}
katang
  • 1,429

1 Answers1

4

Your z axis is log scaled, i.e. the value you set for z filter is the exponent. As you desire to place the contours at 10−4 you have to set z filter/.code={\def\pgfmathresult{-4}}.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
%http://pgfplots.net/tikz/examples/contour-and-surface/
\pgfplotstableset{%
    col sep=semicolon,
    x index=0,
    y index=1,
    z index=2,
    header=false
}%

\begin{filecontents*}{data/XYZ.csv}
   2016; 1;      32.7e-9
   2016;10;      1560e-9
   2016;20;      9811e-9
   2016;25;      5204e-9

   2015; 1;   199e-9
   2015;10;   438e-9
   2015;20;   674e-9
   2015;25;  1718e-9

   2014; 1;    199e-9
   2014;10;   2446e-9
   2014;20;   1893e-9
   2014;25;   2670e-9

   1994; 1;   76957E-9
   1994;10;54545455e-9
   1994;20; 1390462e-9
   1994;25; 1440795e-9

   1993; 1;  1167453e-9
   1993;10;  7484185e-9
   1993;20;  7484185e-9
   1993;25;  8876163e-9
\end{filecontents*}


\begin{document}
\begin{tikzpicture}
\pgfplotsset{
    every axis/.append style={
        scale only axis,
        width=\textwidth,
       height=\textwidth,
        xtick={1995,2000,2005,2010,2015},
        ytick={1,10,20,25},
        ztick={1e-8,1e-6,1e-4,1e-2,1e-0}
    },
    /tikz/every picture/.append style={
        trim axis left,
        trim axis right,
    }
    }
   \begin{axis}
      [ %nodes near coords={(\coordindex)},
    domain=1980:2020,
    domain y=1:40,
      footnotesize,
      title={Hillside},
            /pgf/number format/.cd,
        use comma,
        1000 sep={},
        xlabel=Year,
        ylabel=position,
        xmin=1980, xmax=2020,% x scale
        ymin=1, ymax=40, % y scale
        zmin=1e-12, zmax=1, % z scale
        xlabel=Year,
        zmode = log,
        grid=major,
        grid style={dotted},
        colormap/jet,
        zmode=log,
      ]

\addplot3
[surf]
    table {data/XYZ.csv};

% This is the Z (bottom) projection
    \addplot3[
        contour gnuplot={
            % cdata should not be affected by z filter:
            output point meta=rawz,
            number=15,
            labels=false,
        },
        z filter/.code={\def\pgfmathresult{-4}},
    ]
    table {data/XYZ.csv};
% This is the X projection
    \addplot3[
        domain=1980:2020,
        domain y=1:30,
        % we want 1d (!) individually colored mesh segments:
        mesh, patch type=line,
        x filter/.code={\def\pgfmathresult{1980}},
    ] 
    table {data/XYZ.csv};

%% This is the Y projection
    \addplot3[
        % we want 1d (!) individually colored mesh segments:
        mesh, patch type=line,
        y filter/.code={\def\pgfmathresult{40}},
    ] 
    table {data/XYZ.csv};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Henri Menke
  • 109,596
  • Thank you. Could you please add also comment, WHY it is so? It is not intuitive for me (the axis could be based on 2 or e, or something similar) – katang Aug 10 '16 at 16:37