![在图中坐标附近写入一个值](https://linux22.com/image/309555/%E5%9C%A8%E5%9B%BE%E4%B8%AD%E5%9D%90%E6%A0%87%E9%99%84%E8%BF%91%E5%86%99%E5%85%A5%E4%B8%80%E4%B8%AA%E5%80%BC.png)
我想从文件中执行此操作,而不是像现在一样从文档内部执行此操作:
\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}