# pgfplots: How to plot volume data on the surfaces of a cuboid?

in MATLAB I genrated the plot below. In my task I only have data from the 3 shown slices on the surfaces of a cuboid. I don't have the complete volume information as it seems from the MATLAB code below. Is it possible to realize 3 surface plots on slices of a plotbox with pgfplots?

[x,y,z] = meshgrid(-1:.1:1,-1:.1:1,-1:.1:0);
v = x.*exp(-x.^2-y.^2-z.^2);
xslice = [-1]; yslice = [-1]; zslice = [0];

s1=slice(x,y,z,v,xslice,yslice,zslice)

box on
set(gca,'DataAspectRatio',[1 1 1])
set(s1,'FaceColor','interp',...
'EdgeColor','none')

view([-60, 25])
xlim([-1, 1])
ylim([-1, 1])
zlim([-1, 0])


According to my task I created the following code:

\documentclass[tikz,border=12pt]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots}

\begin{filecontents*}{xslice.dat}
# x     y       z       v
-1.0000000e+00  -1.0000000e+00  -1.0000000e+00  -4.9787068e-02
-1.0000000e+00  -1.0000000e+00  -7.5000000e-01  -7.7111720e-02
-1.0000000e+00  -1.0000000e+00  -5.0000000e-01  -1.0539922e-01
-1.0000000e+00  -1.0000000e+00  -2.5000000e-01  -1.2713573e-01
-1.0000000e+00  -1.0000000e+00   0.0000000e+00  -1.3533528e-01
-1.0000000e+00  -7.5000000e-01  -1.0000000e+00  -7.7111720e-02
-1.0000000e+00  -7.5000000e-01  -7.5000000e-01  -1.1943297e-01
-1.0000000e+00  -7.5000000e-01  -5.0000000e-01  -1.6324551e-01
-1.0000000e+00  -7.5000000e-01  -2.5000000e-01  -1.9691168e-01
-1.0000000e+00  -7.5000000e-01   0.0000000e+00  -2.0961139e-01
-1.0000000e+00  -5.0000000e-01  -1.0000000e+00  -1.0539922e-01
-1.0000000e+00  -5.0000000e-01  -7.5000000e-01  -1.6324551e-01
-1.0000000e+00  -5.0000000e-01  -5.0000000e-01  -2.2313016e-01
-1.0000000e+00  -5.0000000e-01  -2.5000000e-01  -2.6914635e-01
-1.0000000e+00  -5.0000000e-01   0.0000000e+00  -2.8650480e-01
-1.0000000e+00  -2.5000000e-01  -1.0000000e+00  -1.2713573e-01
-1.0000000e+00  -2.5000000e-01  -7.5000000e-01  -1.9691168e-01
-1.0000000e+00  -2.5000000e-01  -5.0000000e-01  -2.6914635e-01
-1.0000000e+00  -2.5000000e-01  -2.5000000e-01  -3.2465247e-01
-1.0000000e+00  -2.5000000e-01   0.0000000e+00  -3.4559075e-01
-1.0000000e+00   0.0000000e+00  -1.0000000e+00  -1.3533528e-01
-1.0000000e+00   0.0000000e+00  -7.5000000e-01  -2.0961139e-01
-1.0000000e+00   0.0000000e+00  -5.0000000e-01  -2.8650480e-01
-1.0000000e+00   0.0000000e+00  -2.5000000e-01  -3.4559075e-01
-1.0000000e+00   0.0000000e+00   0.0000000e+00  -3.6787944e-01
-1.0000000e+00   2.5000000e-01  -1.0000000e+00  -1.2713573e-01
-1.0000000e+00   2.5000000e-01  -7.5000000e-01  -1.9691168e-01
-1.0000000e+00   2.5000000e-01  -5.0000000e-01  -2.6914635e-01
-1.0000000e+00   2.5000000e-01  -2.5000000e-01  -3.2465247e-01
-1.0000000e+00   2.5000000e-01   0.0000000e+00  -3.4559075e-01
-1.0000000e+00   5.0000000e-01  -1.0000000e+00  -1.0539922e-01
-1.0000000e+00   5.0000000e-01  -7.5000000e-01  -1.6324551e-01
-1.0000000e+00   5.0000000e-01  -5.0000000e-01  -2.2313016e-01
-1.0000000e+00   5.0000000e-01  -2.5000000e-01  -2.6914635e-01
-1.0000000e+00   5.0000000e-01   0.0000000e+00  -2.8650480e-01
-1.0000000e+00   7.5000000e-01  -1.0000000e+00  -7.7111720e-02
-1.0000000e+00   7.5000000e-01  -7.5000000e-01  -1.1943297e-01
-1.0000000e+00   7.5000000e-01  -5.0000000e-01  -1.6324551e-01
-1.0000000e+00   7.5000000e-01  -2.5000000e-01  -1.9691168e-01
-1.0000000e+00   7.5000000e-01   0.0000000e+00  -2.0961139e-01
-1.0000000e+00   1.0000000e+00  -1.0000000e+00  -4.9787068e-02
-1.0000000e+00   1.0000000e+00  -7.5000000e-01  -7.7111720e-02
-1.0000000e+00   1.0000000e+00  -5.0000000e-01  -1.0539922e-01
-1.0000000e+00   1.0000000e+00  -2.5000000e-01  -1.2713573e-01
-1.0000000e+00   1.0000000e+00   0.0000000e+00  -1.3533528e-01
\end{filecontents*}

\begin{filecontents*}{yslice.dat}
# x     y       z       v
-1.0000000e+00  -1.0000000e+00  -1.0000000e+00  -4.9787068e-02
-1.0000000e+00  -1.0000000e+00  -7.5000000e-01  -7.7111720e-02
-1.0000000e+00  -1.0000000e+00  -5.0000000e-01  -1.0539922e-01
-1.0000000e+00  -1.0000000e+00  -2.5000000e-01  -1.2713573e-01
-1.0000000e+00  -1.0000000e+00   0.0000000e+00  -1.3533528e-01
-7.5000000e-01  -1.0000000e+00  -1.0000000e+00  -5.7833790e-02
-7.5000000e-01  -1.0000000e+00  -7.5000000e-01  -8.9574726e-02
-7.5000000e-01  -1.0000000e+00  -5.0000000e-01  -1.2243413e-01
-7.5000000e-01  -1.0000000e+00  -2.5000000e-01  -1.4768376e-01
-7.5000000e-01  -1.0000000e+00   0.0000000e+00  -1.5720854e-01
-5.0000000e-01  -1.0000000e+00  -1.0000000e+00  -5.2699612e-02
-5.0000000e-01  -1.0000000e+00  -7.5000000e-01  -8.1622756e-02
-5.0000000e-01  -1.0000000e+00  -5.0000000e-01  -1.1156508e-01
-5.0000000e-01  -1.0000000e+00  -2.5000000e-01  -1.3457317e-01
-5.0000000e-01  -1.0000000e+00   0.0000000e+00  -1.4325240e-01
-2.5000000e-01  -1.0000000e+00  -1.0000000e+00  -3.1783933e-02
-2.5000000e-01  -1.0000000e+00  -7.5000000e-01  -4.9227919e-02
-2.5000000e-01  -1.0000000e+00  -5.0000000e-01  -6.7286587e-02
-2.5000000e-01  -1.0000000e+00  -2.5000000e-01  -8.1163117e-02
-2.5000000e-01  -1.0000000e+00   0.0000000e+00  -8.6397688e-02
0.0000000e+00  -1.0000000e+00  -1.0000000e+00   0.0000000e+00
0.0000000e+00  -1.0000000e+00  -7.5000000e-01   0.0000000e+00
0.0000000e+00  -1.0000000e+00  -5.0000000e-01   0.0000000e+00
0.0000000e+00  -1.0000000e+00  -2.5000000e-01   0.0000000e+00
0.0000000e+00  -1.0000000e+00   0.0000000e+00   0.0000000e+00
2.5000000e-01  -1.0000000e+00  -1.0000000e+00   3.1783933e-02
2.5000000e-01  -1.0000000e+00  -7.5000000e-01   4.9227919e-02
2.5000000e-01  -1.0000000e+00  -5.0000000e-01   6.7286587e-02
2.5000000e-01  -1.0000000e+00  -2.5000000e-01   8.1163117e-02
2.5000000e-01  -1.0000000e+00   0.0000000e+00   8.6397688e-02
5.0000000e-01  -1.0000000e+00  -1.0000000e+00   5.2699612e-02
5.0000000e-01  -1.0000000e+00  -7.5000000e-01   8.1622756e-02
5.0000000e-01  -1.0000000e+00  -5.0000000e-01   1.1156508e-01
5.0000000e-01  -1.0000000e+00  -2.5000000e-01   1.3457317e-01
5.0000000e-01  -1.0000000e+00   0.0000000e+00   1.4325240e-01
7.5000000e-01  -1.0000000e+00  -1.0000000e+00   5.7833790e-02
7.5000000e-01  -1.0000000e+00  -7.5000000e-01   8.9574726e-02
7.5000000e-01  -1.0000000e+00  -5.0000000e-01   1.2243413e-01
7.5000000e-01  -1.0000000e+00  -2.5000000e-01   1.4768376e-01
7.5000000e-01  -1.0000000e+00   0.0000000e+00   1.5720854e-01
1.0000000e+00  -1.0000000e+00  -1.0000000e+00   4.9787068e-02
1.0000000e+00  -1.0000000e+00  -7.5000000e-01   7.7111720e-02
1.0000000e+00  -1.0000000e+00  -5.0000000e-01   1.0539922e-01
1.0000000e+00  -1.0000000e+00  -2.5000000e-01   1.2713573e-01
1.0000000e+00  -1.0000000e+00   0.0000000e+00   1.3533528e-01
\end{filecontents*}

\begin{filecontents*}{zslice.dat}
# x     y       z       v
-1.0000000e+00  -1.0000000e+00   0.0000000e+00  -1.3533528e-01
-7.5000000e-01  -1.0000000e+00   0.0000000e+00  -1.5720854e-01
-5.0000000e-01  -1.0000000e+00   0.0000000e+00  -1.4325240e-01
-2.5000000e-01  -1.0000000e+00   0.0000000e+00  -8.6397688e-02
0.0000000e+00  -1.0000000e+00   0.0000000e+00   0.0000000e+00
2.5000000e-01  -1.0000000e+00   0.0000000e+00   8.6397688e-02
5.0000000e-01  -1.0000000e+00   0.0000000e+00   1.4325240e-01
7.5000000e-01  -1.0000000e+00   0.0000000e+00   1.5720854e-01
1.0000000e+00  -1.0000000e+00   0.0000000e+00   1.3533528e-01
-1.0000000e+00  -7.5000000e-01   0.0000000e+00  -2.0961139e-01
-7.5000000e-01  -7.5000000e-01   0.0000000e+00  -2.4348935e-01
-5.0000000e-01  -7.5000000e-01   0.0000000e+00  -2.2187366e-01
-2.5000000e-01  -7.5000000e-01   0.0000000e+00  -1.3381536e-01
0.0000000e+00  -7.5000000e-01   0.0000000e+00   0.0000000e+00
2.5000000e-01  -7.5000000e-01   0.0000000e+00   1.3381536e-01
5.0000000e-01  -7.5000000e-01   0.0000000e+00   2.2187366e-01
7.5000000e-01  -7.5000000e-01   0.0000000e+00   2.4348935e-01
1.0000000e+00  -7.5000000e-01   0.0000000e+00   2.0961139e-01
-1.0000000e+00  -5.0000000e-01   0.0000000e+00  -2.8650480e-01
-7.5000000e-01  -5.0000000e-01   0.0000000e+00  -3.3281048e-01
-5.0000000e-01  -5.0000000e-01   0.0000000e+00  -3.0326533e-01
-2.5000000e-01  -5.0000000e-01   0.0000000e+00  -1.8290391e-01
0.0000000e+00  -5.0000000e-01   0.0000000e+00   0.0000000e+00
2.5000000e-01  -5.0000000e-01   0.0000000e+00   1.8290391e-01
5.0000000e-01  -5.0000000e-01   0.0000000e+00   3.0326533e-01
7.5000000e-01  -5.0000000e-01   0.0000000e+00   3.3281048e-01
1.0000000e+00  -5.0000000e-01   0.0000000e+00   2.8650480e-01
-1.0000000e+00  -2.5000000e-01   0.0000000e+00  -3.4559075e-01
-7.5000000e-01  -2.5000000e-01   0.0000000e+00  -4.0144607e-01
-5.0000000e-01  -2.5000000e-01   0.0000000e+00  -3.6580781e-01
-2.5000000e-01  -2.5000000e-01   0.0000000e+00  -2.2062423e-01
0.0000000e+00  -2.5000000e-01   0.0000000e+00   0.0000000e+00
2.5000000e-01  -2.5000000e-01   0.0000000e+00   2.2062423e-01
5.0000000e-01  -2.5000000e-01   0.0000000e+00   3.6580781e-01
7.5000000e-01  -2.5000000e-01   0.0000000e+00   4.0144607e-01
1.0000000e+00  -2.5000000e-01   0.0000000e+00   3.4559075e-01
-1.0000000e+00   0.0000000e+00   0.0000000e+00  -3.6787944e-01
-7.5000000e-01   0.0000000e+00   0.0000000e+00  -4.2733712e-01
-5.0000000e-01   0.0000000e+00   0.0000000e+00  -3.8940039e-01
-2.5000000e-01   0.0000000e+00   0.0000000e+00  -2.3485327e-01
0.0000000e+00   0.0000000e+00   0.0000000e+00   0.0000000e+00
2.5000000e-01   0.0000000e+00   0.0000000e+00   2.3485327e-01
5.0000000e-01   0.0000000e+00   0.0000000e+00   3.8940039e-01
7.5000000e-01   0.0000000e+00   0.0000000e+00   4.2733712e-01
1.0000000e+00   0.0000000e+00   0.0000000e+00   3.6787944e-01
-1.0000000e+00   2.5000000e-01   0.0000000e+00  -3.4559075e-01
-7.5000000e-01   2.5000000e-01   0.0000000e+00  -4.0144607e-01
-5.0000000e-01   2.5000000e-01   0.0000000e+00  -3.6580781e-01
-2.5000000e-01   2.5000000e-01   0.0000000e+00  -2.2062423e-01
0.0000000e+00   2.5000000e-01   0.0000000e+00   0.0000000e+00
2.5000000e-01   2.5000000e-01   0.0000000e+00   2.2062423e-01
5.0000000e-01   2.5000000e-01   0.0000000e+00   3.6580781e-01
7.5000000e-01   2.5000000e-01   0.0000000e+00   4.0144607e-01
1.0000000e+00   2.5000000e-01   0.0000000e+00   3.4559075e-01
-1.0000000e+00   5.0000000e-01   0.0000000e+00  -2.8650480e-01
-7.5000000e-01   5.0000000e-01   0.0000000e+00  -3.3281048e-01
-5.0000000e-01   5.0000000e-01   0.0000000e+00  -3.0326533e-01
-2.5000000e-01   5.0000000e-01   0.0000000e+00  -1.8290391e-01
0.0000000e+00   5.0000000e-01   0.0000000e+00   0.0000000e+00
2.5000000e-01   5.0000000e-01   0.0000000e+00   1.8290391e-01
5.0000000e-01   5.0000000e-01   0.0000000e+00   3.0326533e-01
7.5000000e-01   5.0000000e-01   0.0000000e+00   3.3281048e-01
1.0000000e+00   5.0000000e-01   0.0000000e+00   2.8650480e-01
-1.0000000e+00   7.5000000e-01   0.0000000e+00  -2.0961139e-01
-7.5000000e-01   7.5000000e-01   0.0000000e+00  -2.4348935e-01
-5.0000000e-01   7.5000000e-01   0.0000000e+00  -2.2187366e-01
-2.5000000e-01   7.5000000e-01   0.0000000e+00  -1.3381536e-01
0.0000000e+00   7.5000000e-01   0.0000000e+00   0.0000000e+00
2.5000000e-01   7.5000000e-01   0.0000000e+00   1.3381536e-01
5.0000000e-01   7.5000000e-01   0.0000000e+00   2.2187366e-01
7.5000000e-01   7.5000000e-01   0.0000000e+00   2.4348935e-01
1.0000000e+00   7.5000000e-01   0.0000000e+00   2.0961139e-01
-1.0000000e+00   1.0000000e+00   0.0000000e+00  -1.3533528e-01
-7.5000000e-01   1.0000000e+00   0.0000000e+00  -1.5720854e-01
-5.0000000e-01   1.0000000e+00   0.0000000e+00  -1.4325240e-01
-2.5000000e-01   1.0000000e+00   0.0000000e+00  -8.6397688e-02
0.0000000e+00   1.0000000e+00   0.0000000e+00   0.0000000e+00
2.5000000e-01   1.0000000e+00   0.0000000e+00   8.6397688e-02
5.0000000e-01   1.0000000e+00   0.0000000e+00   1.4325240e-01
7.5000000e-01   1.0000000e+00   0.0000000e+00   1.5720854e-01
1.0000000e+00   1.0000000e+00   0.0000000e+00   1.3533528e-01
\end{filecontents*}


As a first step I tried to place the zplane at z=0.However, the resulting plot is far away from my desired plot.

Here goes the relevant part of the code:

\begin{document}

\begin{tikzpicture}
\begin{axis}[view={-60}{25}]

mesh/cols=9,
mesh/ordering=rowwise,
]
table  [x index=0,
y index=1,
z index=3,
z expr=0,
] {zslice.dat};

\end{axis}
\end{tikzpicture}

\end{document}


You need to use explicit point meta data. Then you can specify which column should be used for meta information. Furthermore, the # in the beginning of your files caused an error. Lastly, the x dir and y dir options will probably be helpful when creating the other surfaces.

## Code

\documentclass[tikz,border=12pt]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots}

\begin{filecontents*}{zslice.dat}
x                y               z              v
...
\end{filecontents*}

\begin{document}

\begin{tikzpicture}
\begin{axis}[view={-60}{25}]

[   surf,
mesh/cols=9,
mesh/ordering=rowwise,
point meta=explicit,
x dir=reverse,
y dir=reverse,
] table  [meta=v] {zslice.dat};
\end{axis}
\end{tikzpicture}

\end{document}


## Output

Edit 1: I decided to play around with it a little. As many of the predefined color maps emulate MatLab ones, I guessed that you used jet. The Only thing you need to change for the other planes is the mash/ordering to colwise. Furthermore I learned that axis cs is the default coordinate system starting from version 1.11, so that it's easy to draw the black outlines.

## Code

\documentclass[tikz,border=12pt]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}

\begin{document}

\begin{tikzpicture}
\begin{axis}
[   view={-60}{25},
colormap/jet,
zmin=-1,
zmax=0,
]
[   surf,
mesh/cols=9,
mesh/ordering=rowwise,
point meta=explicit,
x dir=reverse,
y dir=reverse,
] table  [meta=v] {zslice.dat};
[   surf,
mesh/cols=9,
mesh/ordering=colwise,
point meta=explicit,
x dir=reverse,
y dir=reverse,
] table  [meta=v] {yslice.dat};
[   surf,
mesh/cols=9,
mesh/ordering=colwise,
point meta=explicit,
x dir=reverse,
y dir=reverse,
] table  [meta=v] {xslice.dat};
\draw (-1,-1,-1) -- (1,-1,-1) -- (1,-1,0) -- (-1,-1,0) -- cycle;
\draw (-1,-1,-1) -- (-1,1,-1) -- (-1,1,0) -- (-1,-1,0) -- cycle;
\draw (-1,-1,0) -- (-1,1,0) -- (1,1,0) -- (1,-1,0) -- cycle;
\end{axis}

\end{tikzpicture}

\end{document}