# Plotting 3D graphs in specified axial direction in tikz

I am a complete tikz noob and just taking snippets of examples to draw my first diagram. To get my head around orientations I am starting with the polarizing microscope example

I am trying to now plot a sine wave starting from the origin and extending out along the x, y and z directions.

So far the x axis has been quite straight forward:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
[x={(0.866cm,-0.5cm)}, y={(0.866cm,0.5cm)}, z={(0cm,1cm)}, scale=1.0,
%Option for nice arrows
>=stealth, %
inner sep=0pt, outer sep=2pt,%
axis/.style={thick,->},
wave/.style={thick,color=#1,smooth},
polaroid/.style={fill=black!60!white, opacity=0.3},]

% Colors
\colorlet{darkgreen}{green!50!black}
\colorlet{lightgreen}{green!80!black}
\colorlet{darkred}{red!50!black}
\colorlet{lightred}{red!80!black}

% Frame
\coordinate (O) at (0, 0, 0);
\draw[axis] (O) -- +(14, 0,   0) node [right] {x};
\draw[axis] (O) -- +(0,  2.5, 0) node [right] {y};
\draw[axis] (O) -- +(0,  0,   2) node [above] {z};

\draw[thick,dashed] (-2,0,0) -- (O);

% Electric field vectors
\draw[wave=blue, variable=\x,samples at={0,0.25,...,10}]
plot (\x,{sin(2*\x r)},0)node[anchor=north]{$\vec{E}$};

\end{tikzpicture}
\end{document}


resulting in:

But now I have no idea how to change the 'axis' tikz chooses to draw the y and z sine wave. I have tried changing the variables but it just plots them directly over the x one.

-

May be this is what you want:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
[x={(0.866cm,-0.5cm)}, y={(0.866cm,0.5cm)}, z={(0cm,1cm)}, scale=1.0,
%Option for nice arrows
>=stealth, %
inner sep=0pt, outer sep=2pt,%
axis/.style={thick,->},
wave/.style={thick,color=#1,smooth},
polaroid/.style={fill=black!60!white, opacity=0.3},]

% Colors
\colorlet{darkgreen}{green!50!black}
\colorlet{lightgreen}{green!80!black}
\colorlet{darkred}{red!50!black}
\colorlet{lightred}{red!80!black}

% Frame
\coordinate (O) at (0, 0, 0);
\draw[axis] (O) -- +(14, 0,   0) node [right] {x};
\draw[axis] (O) -- +(0,  14, 0) node [right] {y};
\draw[axis] (O) -- +(0,  0,   14) node [above] {z};

\draw[thick,dashed] (-2,0,0) -- (O);

% Electric field vectors
\draw[wave=blue, variable=\x,samples at={0,0.25,...,10}]
plot (\x,{sin(2*\x r)},0)node[anchor=north]{$\vec{E}$};
\draw[wave=red, variable=\y,samples at={0,0.25,...,10}]
plot ({sin(2*\y r)},\y,0)node[anchor=north]{$\vec{E}$};
\draw[wave=green, variable=\z,samples at={0,0.25,...,10}]
plot (0,{sin(2*\z r)},\z)node[anchor=north]{$\vec{E}$};

\end{tikzpicture}
\end{document}


Explanation

When you plot (\x,{sin(2*\x r)},0), tikz plots sin(2*\x r) in the xy plane (in x-direction) and z is zero always. Say you want to plot the funtion in xy plane (in y-direction) and keeping z zero, then you have to use ({sin(2*\y r)},\y,0). Similarly for yz plane with x=0. Now you can try to change the planes in which the graph is plotted. For example, we want sine wave in y direction and lying in yz plane. Then you should use

\draw[wave=red, variable=\y,samples at={0,0.25,...,10}]
plot (0,\y,{sin(2*\y r)})node[anchor=north]{$\vec{E}$};


which will give

-
That is amazing! Thank you very much. It was the x-y plane thing I did not understand at all. – Steve Hatcher Feb 14 '14 at 6:14
@SteveHatcher You are welcome. Glad it helped :) – Harish Kumar Feb 14 '14 at 12:36