11

I have a table with numerical data and text in different columns, like this:

0   0   0.1
1   0   \pi
2   0   \frac{\pi}{2}

I'd like to put text labels on a plot using the text in the third column at the position given by the first two columns (I need to overlay these text labels on a plot at given positions). Is it possible with pgfplots?

14

Yes, that is possible. You'll need to tell pgfplots to expect symbolic meta data (so it doesn't try to parse it as numbers), which you do using the key point meta=explicit symbolic.

Since you're using math commands in your labels, you'll have to make sure they are typeset in math mode. You can do this using nodes near coords=$\pgfplotspointmeta$.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{data.dat}
0   0   0.1
1   0   \pi
2   0   \frac{\pi}{2}
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    nodes near coords=$\pgfplotspointmeta$,
    point meta=explicit symbolic
]
\addplot table [meta index=2] {data.dat};
\end{axis}
\end{tikzpicture}
\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.