是否可以从绘图坐标获取并存储特定的 y 值,以便可以将其打印到其他地方(例如,在节点内部)?
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}
\begin{filecontents}{data-fake5.dat}
x y
1 0
2 3
3 1
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line*=bottom,
axis y line*=left,
]
\addplot[name path=myplot] table[x=x,y=y] {data-fake5.dat};
%\node at (1,1.5){\printy{myplot}{2}}; %this should print the y value of the plot 'myplot` associated with x=2, which is 3
\end{axis}
\end{tikzpicture}
\end{document}
期望结果:
答案1
唯一棘手的是行从 0 开始编号,并且头部 (xy) 不算数。
\documentclass{standalone}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}
\begin{filecontents}{data-fake5.dat}
x y
1 0
2 3
3 1
\end{filecontents}
\begin{document}
\pgfplotstableread{data-fake5.dat}\data
\begin{tikzpicture}
\begin{axis}[
axis x line*=bottom,
axis y line*=left,
]
\addplot[name path=myplot] table[x=x,y=y] {\data};
%\pgfplotsextra{\pgfplotstablegetelem{1}{y}\of{\data}}% alternate location
%\node at (1,1.5) {\pgfplotsretval};
\node at (1,1.5) {\pgfplotstablegetelem{1}{y}\of{\data}\pgfplotsretval};
\end{axis}
\end{tikzpicture}
\end{document}