TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have loads of pgfplots which have one thing in common, they all containt one or two addplot with four points that I want to label with the same labels, namely: \tau_c= n \theta. Lets for simplicity say n is 1, 2,3 and 4. Using foreach loop variable as node label in pgfplots looks very much like something that could solve my problem. But how do I append this (or similar) solution when the coordinates are given as in the MWE below? My pgfplots are generated with matlab2tikz and are as mentioned quite numerous, so I would like to avoid having to manipulate the existing file too much.


\usepackage{tikz, pgfplots}

% [spy using outlines={rectangle,black,magnification=3,connect spies}]
unbounded coords=jump,
scale only axis,
title={Case 11},
% legend style={draw=black,fill=white,legend cell align=left}
\addplot [
only marks,
mark options={solid},
forget plot
table[row sep=crcr]{
2.17534491233797 1.76417509678952\\
1.70352168717505 2.47466020520172\\
1.50385056450878 3.36056987643388\\
1.39330071637349 4.41283273476325\\
share|improve this question
up vote 9 down vote accepted

You can use the nodes near coords function for that. If you add

    nodes near coords={
        $\nValue \theta$%

to your document, the node labels will be printed without you having to touch the matlab2tikz-generated code at all:

If you want to be able to provide arbitrary labels that don't directly depend on the coordinate index, you can use a PGF math array that stores the strings for the labels and access that array within the nodes near coords:

    nodes near coords={

share|improve this answer
Amen! Is it possible to somehow make the nodes near coords append to only one or two of many addplots in the same axis environment? Somehow label the addplot, maybe? – Holene Jun 1 '13 at 22:12
@Holene: You can just put the nodes near coords={...} in the \addplot[...] options for the relevant plot. – Jake Jun 1 '13 at 22:13
Thanks! You just saved my night =) – Holene Jun 1 '13 at 22:14
Oh, sorry for the quick return; what if I would have n to be a macro? For instance \sfrac{1}{2}... – Holene Jun 1 '13 at 22:17
May I upvote twice, please? – Holene Jun 1 '13 at 22:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.