I'm trying to create a 3D heatmap using data from a .txt file in the following format (tabs instead of spaces):
data.txt
x y z data
0 0 0 1.0
0 0 1 1.6
0 0 2 13.0
0 1 0 1.7
0 1 1 11.0
0 1 2 18.6
0 2 0 4.9
0 2 1 4.3
0 2 2 1.2
1 0 0 1.0
1 0 1 1.6
1 0 2 13.0
1 1 0 1.7
1 1 1 11.0
1 1 2 18.6
1 2 0 4.9
1 2 1 4.3
1 2 2 1.2
2 0 0 1.0
2 0 1 1.6
2 0 2 13.0
2 1 0 1.7
2 1 1 11.0
2 1 2 18.6
2 2 0 4.9
2 2 1 4.3
2 2 2 1.2
I want the plot to consist of cubes which are flush with one another and do not exceed the axes, whose colors are reasonably visible using suitable opacity settings. A good example of what I'm after is this:
which was produced using Mathematica at https://mathematica.stackexchange.com/questions/17260/3d-heatmap-density-plot. I'm looking for a similar result using pgfplots, but with axes labels and a colorbar. Following this I then want to try and remove the nearest few corner cubes (from the viewers perspective) to get an inside look at the cube, like a cross section. For a 3x3x3 cube this would consist of removing the 7 cubes closest to the perspective of the viewer. The tikzpicture code I have so far is:
\documentclass{article}
\usepackage{xcolor}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[width=100pt, height=100pt, view={120}{40},
enlargelimits=false,
xmin=0,xmax=2,
ymin=0,ymax=2,
zmin=0,zmax=2,
colormap/hot,
colorbar,
colorbar style={title=Value, yticklabel style={/pgf/number format/.cd, fixed, precision=1, fixed zerofill},},
point meta min=1,
point meta max=20,
matrix plot*/.append style={opacity=0.5},
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
xtick={0, 1, 2},
ytick={0, 1, 2},
ztick={0, 1, 2}]
\addplot [point meta=explicit, mesh/cols=3] table [meta=data] {data.txt}
\end{axis}
\end{tikzpicture}
\end{document}
This draws the axes the way I'd like but does not plot the data. In fact, when including the \addplot it does not compile. Note that the example data here is for a 3x3x3 cube, but other data may be for a 5x5x5 cube or larger. I'm by no means an expert with pgfplots, so any pointers on how to achieve these goals are welcome.




\documentclass{...}, the required\usepackage's,\begin{document}, and\end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Skillmon Apr 06 '18 at 18:23data.txtwould come in handy. – Skillmon Apr 06 '18 at 18:24