I have a matrix of size MxN and I want to make a surface plot directly from above so that each cell in the matrix is drawn as a square. None of the pgfplots shaders really do what I want, since they draw squares between the cells of the matrix (i.e. a 3x3 matrix ends up as 2x2 cells when plotted). The example hopefully makes it clearer:
\documentclass{article}
\usepackage{fullpage}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotstableread{
0 0 0
0 1 1
0 2 2
1 0 3
1 1 4
1 2 5
2 0 6
2 1 7
2 2 8
}\data
\begin{document}
\foreach \shader in {interp, flat, flat corner} {
\begin{tikzpicture}
\begin{axis}[
title={\texttt{\shader}},
title style={
at={(0.5, 1.5)},
anchor=north,
},
width=.3\linewidth,
view={0}{90},
colormap/hot2,
colorbar horizontal,
colorbar style={
at={(0.5, 1.02)},
anchor=south,
xticklabel pos=upper,
},
]
\addplot3 [surf, shader=\shader] table {\data};
\end{axis}
\end{tikzpicture}
}
\end{document}
How do I arrange my data so that each cell in the matrix is drawn as a separate cell in the output?
EDIT: I realised after entering the question that the answer is very simple, so I'll just answer this myself.