我想在图形中设置带有手动锚点的标签,以便读取标题,并尝试应用到目前为止我所读到的所有内容。我有一个外部数据文件,如下所示。问题是以“每个节点靠近 coord/.append 样式”开头的行会产生错误,提示:
Package PGF Math Error: Unknown function `thisrow_unavailable_load_table_directly' (in 'thisrow_unavailable_load_table_directly')
我在这里,被封锁了。欢迎任何帮助。我制作了一个 MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,graphicx,pgfplots,siunitx}
\usepgfplotslibrary{units}
\usepackage{pgfplotstable}
\pgfplotstableset{col sep=semicolon}
\pgfplotsset{compat=1.12}
\begin{filecontents}{aircraft.txt}
aircraft mph knots kph introduction ancre
Boeing-247 188 160 303 1933 east
Douglas-DC3 207 180 333 1936 east
DC4 227 197 365 1942 east
Lockheed-049 313 271 504 1946 west
DC-6B 311 270 501 1947 east
DC-7C 359 312 578 1953 east
DC-8 588 510 946 1958 north
B707 570 495 917 1958 west
B747-100 554 481 892 1966 south
B747-300 567 493 912 1980 south
B747-400 570 495 917 1985 north
\end{filecontents}
\pgfplotstableread{aircraft.txt}{\aircraft}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\begin{axis} [
width=0.95\textwidth,
xtick pos=left, x unit=m, x unit prefix=k,
ytick pos=left, y unit=m/h, y unit prefix=k, ylabel={Cruise speed},
clip=false ]
\addplot+[
nodes near coords, point meta=explicit symbolic,
visualization depends on={value \thisrow{ancre}\as\myanchor},
every node near coord/.append style={font=\tiny,anchor=\myanchor}
] table [x={introduction}, y={kph},meta={aircraft}] {\aircraft};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
事实证明,预加载表和内联表之间存在差异。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,graphicx,pgfplots,siunitx}
\usepgfplotslibrary{units}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}
\begin{filecontents}{aircraft.txt}
\end{filecontents}
\pgfplotstableread{aircraft.txt}{\aircraft}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\begin{axis} [
width=0.95\textwidth,
xtick pos=left, x unit=m, x unit prefix=k,
ytick pos=left, y unit=m/h, y unit prefix=k, ylabel={Cruise speed},
clip=false ]
\addplot+[
nodes near coords, point meta=explicit symbolic,
visualization depends on={value \thisrow{position}\as\myposition},
every node near coord/.style={font=\tiny,\myposition}
] table [x={introduction}, y={kph},meta={aircraft}] {
aircraft mph knots kph introduction position
Boeing-247 188 160 303 1933 below
Douglas-DC3 207 180 333 1936 {below right}
DC4 227 197 365 1942 right
Lockheed-049 313 271 504 1946 left
DC-6B 311 270 501 1947 right
DC-7C 359 312 578 1953 right
DC-8 588 510 946 1958 above
B707 570 495 917 1958 left
B747-100 554 481 892 1966 below
B747-300 567 493 912 1980 below
B747-400 570 495 917 1985 above
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
一些评论
(正如@Zarko 所问)
在pgfplotscoordprocessing.code.tex
6345-6352 行中有
% These macros are-unfortunately- not accessable here. And the % worst is: error messages are impossible either because they are % not executed... try to provide useful hints: \def\thisrow##1{thisrow_unavailable_load_table_directly}% \def\thisrowno##1{thisrowno_unavailable_load_table_directly}% % this should work. \def\getthisrow##1##2{\pgfplotstablegetelem{\coordindex}{##1}\of{#3}{##2}}% \def\getthisrowno##1##2{\pgfplotstablegetelem{\coordindex}{[index]##1}\of{#3}{##2}}%
这是错误消息中唯一一次出现该字符串。因此我们可能猜测您的文档由于与表源有关的某种原因遇到了这些行,然后停止了。
作者建议我们\getthisrow
在 上使用。但是,如果可能的话,在 内部\thisrow
使用会很困难,因为后者的解析器需要。到目前为止,这就是我能说的全部。\getthisrow
visualization depends on=
\as