7

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}
8

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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