point meta
PGFplots 手册修订版 1.12(2015/01/31)第 186 页给出了使用示例:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[colorbar]
%\addplot[mesh,point meta=y,thick] {x^2}; % WORKS!
\addplot+[point meta=explicit] coordinates
{%
(0,0) [1.0e10]
(1,2) [1.1e10]
(2,3) [1.2e10]
(3,4) [1.3e10]
}; % DOES NOT WORK! WHY NOT?
\end{axis}
\end{tikzpicture}
\end{document}
但图表的颜色到处都是蓝色。代码有什么问题?
答案1
您必须在命令中添加mesh
或选项。surf
\addplot+
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[colorbar]
%\addplot+[mesh,point meta=y,thick] {x^2}; % WORKS!
\addplot+[mesh,point meta=explicit] coordinates
{%
(0,0) [1.0e10]
(1,2) [1.1e10]
(2,3) [1.2e10]
(3,4) [1.3e10]
};
\end{axis}
\end{tikzpicture}
\end{document}