# Add a vertical line to tikzpicture plot

So I havethe code below to create a plot. Now I need to add a vertically dotted line at x = 1.5. Is it possible?

\documentclass[
12pt, % font size
a4paper, % paper format
oneside, % one-sided pages
]{report}

\usepackage{tikz} % draw figures
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\usepackage{pgfplots} % discret signals

% math
\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}
\datavisualization [school book axes,
visualize as smooth line/.list={one,two,three},
y axis={label={$u(t)$}},
x axis={label={$t$}},
one={style={black}},
two={style={red}},
three={style={orange}}]

data [set=one,format=function] {
var x : interval [-3:3];
func y = sin((\value x) r );
}

data [set=two,format=function] {
var x : interval [-3:3];
func y = sin((1.5 - \value x) r);
};
\end{tikzpicture}

\end{document}

• Could you please post a MWE, including the headers ? I am not able to compile this code and do not know which package is missing. Mar 2 '17 at 8:50
• As an addition to the given answers, if you want to draw the line to one of the sine functions, you can use {sin(x)} as a y-coordinate (braces are needed to hide the parentheses from the parser), e.g. \draw[dashed] (1.5,0) -- (1.5,{sin(1.5 r)}); Mar 2 '17 at 9:03

Just use \draw [dashed] (x1,y1) -- (x2,y2); . For example from -1 to 1:

You can use loosely dashed, densely dashed, loosely dotted, and densely dotted (Tikz manual:http://ftp.fau.de/ctan/graphics/pgf/base/doc/pgfmanual.pdf, See 2.9 Drawing options page 34 or 15.3.2 Graphic Parameters: Dash Pattern p.167)

MWE:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{datavisualization.formats.functions}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\datavisualization [school book axes,
visualize as smooth line/.list={one,two,three},
y axis={label={$u(t)$}},
x axis={label={$t$}},
one={style={black}},
two={style={red}},
three={style={orange}}]

data [set=one,format=function] {
var x : interval [-3:3];
func y = sin((\value x) r );
}

data [set=two,format=function] {
var x : interval [-3:3];
func y = sin((1.5 - \value x) r);
};

\draw [dashed] (1.5,-1) -- (1.5,1);
\end{tikzpicture}

\end{document}


The easiest way is probably to add

\draw[dashed] (1.5,0) -- (1.5,1);


by the end of your code. And you can change the y coordinates of (1.5,0) and (1.5,1) to make your line longer.