3

I want to do it from a file, rather from inside the document like I do it now:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        title = My title,
        xlabel = {$x$},
        ylabel = {$y$},
        legend entries = {A},
    ]
    \addplot [nodes near coords, mark = *, blue, point meta = explicit symbolic] %table {Measurements/A.dat};
    table[meta = label] {
        x     y    label
        0    10  0
        0.1  9   0.1
        0.5  6   0.5
        0.9  5   0.9
    };
    \end{axis}
\end{tikzpicture}
\end{document}

My file is like this, but I am OK in changing the format if needed:

x_0 f(x) label
# some comment line
0    10  0
0.1  9   0.1
0.5  6   0.5
0.9  5   0.9

In other words, I want to just write

table {Measurements/A.dat};

and have my data in A.dat file, instead of writing the data inside the .tex:

table[meta = label] {
  x     y    label
  0     10   0
  ...
};

Is this possible? Could not find the solution in the manual.

2

Replace

table

with

table[meta = label]

and you should be fine.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{mydata.dat}
  x_0 f(x) label
  %some comment
0    10  0
0.1  9   0.1
0.5  6   0.5
0.9  5   0.9
\end{filecontents*}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        title = My title,
        xlabel = {$x$},
        ylabel = {$y$},
        legend entries = {A},
        every node near coord/.append style={anchor=south west},
    ]
    \addplot [nodes near coords, mark = *, blue, point meta = explicit symbolic] %table {Measurements/A.dat};
    table[meta = label] {mydata.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • Did the trick. I edited your answer, but it is peer reviewed, hope you do not mind. :) – gsamaras Apr 16 '15 at 23:27
  • 1
    @G.Samaras Feel free. :-) – user11232 Apr 16 '15 at 23:34

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.