I am puzzled by something in tikzpicture. Here is the problematic code that i shrinked to its minimum:
\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\begin{document}
\newcommand{\Table}{
\begin{tikzpicture}
\begin{axis}
\foreach \A / \B/ \C in {1/100/g, 2/200/h}
\addplot [
mark=diamond*,
nodes near coords={g}]
coordinates {(\B, \A)};
\end{axis}
\end{tikzpicture}
}
\Table
\end{document}
This code works well and adds the label g next to the markers.
But i would like this label to be a variable in the foreach loop.
So i replace
nodes near coords={g} by nodes near coords={\C}
But then I got an 'undefined control sequence' error. Could someone explain why is this the case? And also possible way to fix it?
Thanks in advance.

pgfplotstableloadspgfplots,pgfplotsloadstikzandtikzloadsxcolor. So, it is sufficient to just load thepgfplotstablepackage. But you should add\pgfplotsset{compat=1.18}as noted in a warning you should get. – Jasper Habicht Sep 12 '23 at 13:17\addplots directly (or at least not all of it) but caches things for later. At that point\Cisn't either defined anymore (because\foreachgroups its body) or\Cis just the last item (when a loop is used that doesn't group its body). – Qrrbrbirlbel Sep 12 '23 at 14:37