4

This tikz code automatically output a node with the y value on the plot... However, how can I colour the text black ??? (now it's blue)

    \definecolor{mycolor1}{rgb}{0.20810,0.16630,0.52920}%
    \begin{tikzpicture}
    \begin{axis}[%
    width=0.5092\figurewidth,
    height=\figureheight,
    at={(0\figurewidth,0\figureheight)},
    scale only axis,
    xmin=0,
    xmax=7,
    xmajorgrids,
    ymin=0,
    ymax=100,
    ymajorgrids,
    nodes near coords={%
    %   $(\pgfmathprintnumber
    %   {\pgfkeysvalueof{/data point/x}},
    $   \pgfmathprintnumber
        {\pgfkeysvalueof{/data point/y}}$%
        }
    ]
    \addplot [color=mycolor1,solid,line width=2.0pt,forget plot]
      table[row sep=crcr]{%
    1   76.32\\
    2   71.26\\
    3   69.84\\
    4   64.62\\
    5   57.81\\
    6   56.67\\
    };
    \end{axis}
    \end{tikzpicture}%     

Thank you!

  • 1
    Please post a complete example. We need to be able to copy-paste-compile in order to help effectively. Impossible to say why it is blue right now. – cfr Mar 29 '15 at 0:19
  • I forgot the first line \definecolor{mycolor1}{rgb}{0.20810,0.16630,0.52920}% – Kevin Mar 29 '15 at 0:23
5

Use every node near coord/.style={black} in the options.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
      \begin{tikzpicture}
    \begin{axis}[%
    width=\linewidth,
    scale only axis,
    xmin=0,
    xmax=7,
    ymin=0,
    ymax=100,
    grid=major,
    nodes near coords={%
    %   $(\pgfmathprintnumber
    %   {\pgfkeysvalueof{/data point/x}},
    $   \pgfmathprintnumber
        {\pgfkeysvalueof{/data point/y}}$%
        },
    every node near coord/.style={black}
    ]
    \addplot [color=red,solid,line width=2.0pt,forget plot]
      table[row sep=crcr]{%
    1   76.32\\
    2   71.26\\
    3   69.84\\
    4   64.62\\
    5   57.81\\
    6   56.67\\
    };
    \end{axis}
    \end{tikzpicture}%
\end{document}

enter image description here

  • I've got to wait 3 minuts before I can accept this answer :D! Thank you so much!!! – Kevin Mar 29 '15 at 0:26

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.