tikz:\pgfkeysvalueof 和文本颜色!

tikz:\pgfkeysvalueof 和文本颜色!

tikz代码自动在图上输出一个带有 y 值的节点...但是,我怎样才能将文本涂成黑色?(现在是蓝色)

    \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}%     

谢谢你!

答案1

every node near coord/.style={black}在选项中使用。

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

在此处输入图片描述

相关内容