我的数据基本上是 3D(x、y 和温度),一个简单的顶视图 3D 图pgfplots
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={0}{90}]
\addplot3[surf] coordinates {
(-1.5,-1.5, 20) (-0.5,-1.5,21) (0.5,-1.5, 22) (1.5,-1.5,21)
(-1.5,-0.5, 21) (-0.5,-0.5,23) (0.5,-0.5, 22) (1.5,-0.5,20)
(-1.5,0.5, 22) (-0.5,0.5,23) (0.5,0.5, 24) (1.5,0.5,21)
(-1.5,1.5, 21) (-0.5,1.5,20) (0.5,1.5, 21) (1.5,1.5,22)
};
\end{axis}
\end{tikzpicture}
\end{document}
看起来像这样:
但是,每个点代表一个 1x1 的正方形,因此上面的图应该有 16 个而不是 9 个图块,并且跨度从 (-2,-2) 到 (2,2)。
我怎样才能做到这一点?
答案1
对于这种类型的图,您应该使用matrix plot
以下选项(如果您希望 y 轴从上到下)或matrix plot*
(如果您希望 y 轴从下到上):
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
axis equal image,
colormap/viridis
]
\addplot3[matrix plot*] coordinates {
(-1.5,-1.5, 20) (-0.5,-1.5,21) (0.5,-1.5, 22) (1.5,-1.5,21)
(-1.5,-0.5, 21) (-0.5,-0.5,23) (0.5,-0.5, 22) (1.5,-0.5,20)
(-1.5,0.5, 22) (-0.5,0.5,23) (0.5,0.5, 24) (1.5,0.5,21)
(-1.5,1.5, 21) (-0.5,1.5,20) (0.5,1.5, 21) (1.5,1.5,22)
};
\end{axis}
\end{tikzpicture}
\end{document}