我正在尝试使用两个数据系列生成一个图,并且仅在其中一个系列上显示标签,而不显示另一个系列。在下面的例子中,我希望在第一个 \addplot 上看到标签,但在第二个上看不到。
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\begin{axis}
[xlabel={$\beta_G$},ylabel={E$_{Peak}$/E$_{acc}$},
xmin=0.45, xmax=1.05,
ymin=1.5, ymax=5.5,
nodes near coords,
every node near coord/.append style={anchor=west},
point meta=explicit symbolic]
\addplot [red, only marks] table[x index=0,y index=1, meta index = 2] {Data.txt};
\addplot [blue] table[x index=0,y index=3] {Data.txt} ;
\end{axis}
\end{tikzpicture}
\caption{Two data series.}
\label{fig:two}
\end{figure}
文件 Data.txt 如下所示:
#X_value Y_value Label Fit
1 0.6 One 0.5
1.1 0.65 two 0.6
1.2 0.7 three 0.75
%------------------- 编辑版本
\documentclass{article}
\usepackage{pgfplots}
\tikzstyle{every node}=[font=\footnotesize]
\pgfplotsset{compat = 1.3,width=7.5cm, height = 5cm}
\begin{filecontents}{Data.txt}
X_value Y_value Label Fit
1.0 0.6 One 0.5
1.1 0.65 two 0.6
1.2 0.7 three 0.75
\end{filecontents}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\begin{axis}
[xlabel={x},ylabel={y},
xmin=0.5, xmax=1.5,
ymin=0, ymax=1,
nodes near coords,
every node near coord/.append style={anchor=west},
point meta=explicit symbolic]
\addplot [red, only marks] table[x index=0,y index=1, meta index = 2] {Data.txt};
\addplot [blue] table[x index=0,y index=3] {Data.txt} ;
\end{axis}
\end{tikzpicture}
\caption{Two data series.}
\label{fig:two}
\end{figure}
\end{document}
以下是我收到的错误消息:
! Package pgfplots Error: could not access the 'point meta' (used for example by scatter plots and color maps). Maybe you need to add '\addplot[point meta=y]' or something like that?.
如果我注释掉两个 \addplot 命令中的任何一个,它就会起作用。