TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

I just started to use pgfplots and I'm trying to plot the line x=3 (a line parallel to the y axis where x is 3). I've tried to find an answer on the net, but all the examples always show how to ploy cases of y=..., and not the other way around.

I should point out that the graph contains more than one plot (if it matters).

share|improve this question
up vote 9 down vote accepted

One way to do this is to use \addplot coordinates. Or, as Jake suggested one could let the second coordinate be the variable (3,x)

enter image description here


\usepackage[paperwidth=21.0cm]{geometry}% for image capture

\begin{axis}[xlabel=$x$, ylabel=$y$] 
    \addplot[color=red,mark=none, ultra thick]  coordinates {(3,-3) (3,3) };
\begin{axis}[ xlabel=$x$, ylabel=$y$] 
    \addplot[color=red,mark=none, ultra thick] (3,x);
share|improve this answer

You could also simply draw anything in TikZ into your axis.

\begin{axis}[xlabel=$x$, ylabel=$y$]
    \addplot[color=red,mark=none, ultra thick] {x^2};
    \draw [blue] (axis cs:3,-1000)--(axis cs:3,1001);

Just a line drawn onto the axis

The axis still clips whatever you draw. This way you can exceed the limits and draw into the enlarged margin. Also you can draw anything you might want and the legend does not get confused.

share|improve this answer
Even simpler would be \draw [blue] (axis cs:3,\pgfkeysvalueof{/pgfplots/ymin})--(axis cs:3,\pgfkeysvalueof{/pgfplots/ymax}); – Qrrbrbirlbel Jan 14 '13 at 14:50

Your Answer


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.