我想从文件中执行此操作,而不是像现在一样从文档内部执行此操作:
\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}
我的文件是这样的,但如果需要的话我可以更改格式:
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
换句话说,我只想写
table {Measurements/A.dat};
并将我的数据存储在A.dat
文件中,而不是将数据写入其中.tex
:
table[meta = label] {
x y label
0 10 0
...
};
这可能吗?无法在手动的。
答案1
代替
table
和
table[meta = label]
你应该会没事的。
\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}