通常,我会使用(a, b |- c, d)
来获取坐标。但是当和处于不同的坐标系中(a, d)
时我该怎么办?具体来说,我的第一个坐标是(来自),第二个坐标就是。此外,我使用的是符号 x 坐标,因此指定为。(a, b)
(c, d)
(axis cs:a, b)
pgfplots
(c, d)
a
{foobar}
\documentclass{article}
\usepackage{fullpage}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[symbolic x coords={{foo}, {bar}}]
\addplot [] coordinates {
({foo}, 0)
({bar}, 0)
};
% Works fine:
\draw [->, green] (axis cs:{foo}, 0.1) -- (axis cs:{bar}, 0.1);
% Package PGF Math Error: Could not parse input ' 0 |- 0' as a floating point
% number, sorry. The unreadable part was near '|- 0'..
\draw [->, red] (axis cs:{foo}, 0 |- 0, -0.1) -- (axis cs:{bar}, 0 |- 0, -0.1);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
使用括号对坐标进行分组:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[symbolic x coords={{foo}, {bar}}]
\addplot [] coordinates {
({foo}, 0)
({bar}, 0)
};
% Works fine:
\draw [->, green] (axis cs:{foo}, 0.1) -- (axis cs:{bar}, 0.1);
\draw [->, red] ({axis cs:{foo}, 0} |- 0, -0.1) -- ({axis cs:{bar}, 0} |- 0, -0.1);
\end{axis}
\end{tikzpicture}
\end{document}