9

Usually, I would use (a, b |- c, d) to get the coordinate (a, d). But what do I do when (a, b) and (c, d) are in different coordinate systems? In particular, my first coordinate is (axis cs:a, b) (from pgfplots) and the second coordinate is simply (c, d). In addition, I'm using symbolic x coordinates, so a is specified as {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}
6

Use braces to group the coordinates:

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.