Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Does anyone know how to set up pgfplots to print nodes only for one and not for all plots?

For example, in 1 I would like to see the nodes only for the test-plot and not for the trend-plot. You will find tex-code for 1 below. Thx :-)

Nodes near coords

\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}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You can just supply the nodes near coords options to the \addplot command instead of to the 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}
share|improve this answer
1  
Thanks, Jake! Did not know that it is that easy :-) –  MaKa TaBo Dec 7 '11 at 13:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.