TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}
share|improve this question
up vote 6 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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