Take the 2-minute tour ×
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.

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

2 Answers 2

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

Code:

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

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

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

\begin{tikzpicture}
\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);
\end{axis}
\end{tikzpicture}

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
2  
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

 
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.