# pgfplots: Set point meta

Related question (among others): Generic point labels in pgfplots

I wish to set the labels of points in my graph to some given string values (ideally defined by a previous macro). Apparently there are tricks involving the point meta key but if I understand correctly those can only be set to numerical values.

The following returns the labels "Point number 1", "Point number 2", etc. i.e. text expressions but that is limited to expressions that one can evaluate from the \coordindex macro.

Note that a \newcommand{\mynames} such that \mynames{1} expands to "First", \mynames{2} to "Second", etc. should be sufficient but I do not know how to code that.

\documentclass{standalone}
\usepackage{pgfplots}

%\pgfplotsset{compat = 1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\newcommand{\samplepoints}{0,2,4}
nodes near coords={\pgfmathtruncatemacro\nValue{\coordindex+1} Point number \nValue},
%   nodes near coords/.expanded={First, Second, Third}, % I wish this worked
] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}


If there is a solution to do that I don't know it. But why don't you simply create in inline table with the \samplepoints and directly give them the meta value which than can easily be plotted?

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
point meta=explicit symbolic,
nodes near coords,
] table [
x=x,
y expr=x^2,
meta=meta,
] {
% (use empty brackets for "no entry")
x   meta
0   First
2   Second
3   {}
4   Third
};
\end{axis}
\end{tikzpicture}
\end{document}


• You can also add an empty value by means of curly braces, i.e. 3 {} – Christian Feuersänger Oct 23 '16 at 13:01
• Of course ... If have edited my answer accordingly. Many thanks for the hint. – Stefan Pinnow Oct 27 '16 at 14:46