有人知道如何设置 pgfplots 来仅为一个图打印节点而不是为所有图打印节点吗?
例如,在1我希望只查看测试图的节点,而不是趋势图的节点。您将找到以下 tex-code:1以下。谢谢 :-)
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[htb]
\centering
\footnotesize
\begin{tikzpicture}
\begin{axis}[
width=\columnwidth,
height=5cm,
xtick=data,
legend style={at={(0.5,-0.2)}, anchor=north, legend columns=-1},
ymin=0,
ymax=2,
xminorgrids=true,
enlarge x limits=0.03,
enlarge y limits=0.07,
every node near coord/.style={font=\tiny},
nodes near coords
]
\addlegendentry{Test}
\addplot+[black, sharp plot, only marks, mark options={mark=*, scale=1.0, fill=black, draw=black}] coordinates {
(1,1.37) (2,1.24) (3,1.33) (4,1.04) (5,1.06) (6,0.82) (7,1.60) (8,0.85) (9,1.1) (10,1.03)
};
\addlegendentry{Trend}
\addplot [lightgray, mark=none, sharp plot, line width=0.6pt] coordinates {
(1,1.15) (2,1.14) (3,1.14) (4,1.14) (5,1.14) (6,1.14) (7,1.14) (8,1.13) (9,1.13) (10,1.13)
};
\end{axis}
\end{tikzpicture}
\caption{test}
\label{dia:test}
\end{figure}
\end{document}
答案1
您可以只nodes near coords
向\addplot
命令提供选项,而不是axis
:
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[htb]
\centering
\footnotesize
\begin{tikzpicture}
\begin{axis}[
width=\columnwidth,
height=5cm,
xtick=data,
legend style={at={(0.5,-0.2)}, anchor=north, legend columns=-1},
ymin=0,
ymax=2,
xminorgrids=true,
enlarge x limits=0.03,
enlarge y limits=0.07,
every node near coord/.style={font=\tiny}
]
\addlegendentry{Test}
\addplot+[
nodes near coords,black, sharp plot, only marks, mark options={mark=*, scale=1.0, fill=black, draw=black}] coordinates {
(1,1.37) (2,1.24) (3,1.33) (4,1.04) (5,1.06) (6,0.82) (7,1.60) (8,0.85) (9,1.1) (10,1.03)
};
\addlegendentry{Trend}
\addplot [lightgray, mark=none, sharp plot, line width=0.6pt] coordinates {
(1,1.15) (2,1.14) (3,1.14) (4,1.14) (5,1.14) (6,1.14) (7,1.14) (8,1.13) (9,1.13) (10,1.13)
};
\end{axis}
\end{tikzpicture}
\caption{test}
\label{dia:test}
\end{figure}
\end{document}