# Merging plots in TikZ

Is there a way to get the second plot at position "HERE" of the first plot?

MWE:

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}

%% First plot
\begin{tikzpicture}[scale=1.5, domain=0:2*pi]
\draw[very thin,color=gray] (0, 2*pi);
\draw[->] (0,0) -- (2*pi,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$y$};
\draw[color=blue]   plot (\x,{sin(\x r)});
\node[below left, red] at (0, -1.2) {HERE};
\end{tikzpicture}

% Second plot
\begin{tikzpicture}[scale=1.5, domain=0:2*pi, rotate=-90]
\draw[very thin,color=gray] (0, 2*pi);
\draw[->] (0,0) -- (2*pi,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$y$};
\draw[color=blue]   plot (\x,{cos(\x r)});
\end{tikzpicture}

\end{document}

-
Is this for projecting the rotation of circle onto sine and cosine plots? – percusse May 11 '13 at 20:40

You can put the second plot in a scope within the first tikzpicture and shift it to where you'd like it. The shifting values should probably be adjusted, I don't know exactly how you want it. By rotating around the origin, it is perhaps easier to find out the shifting values.

There's a problem with the bounding box though, a lot of empty space is added above the plot. You can fix that by saving suitable coordinates for the corners, reset the bounding box, then use the saved coordinates to define a new bounding box.

\documentclass[12pt,border=2mm]{standalone}
\usepackage{tikz}

\begin{document}

%% First plot
\begin{tikzpicture}[scale=1.5, domain=0:2*pi]
\draw[very thin,color=gray] (0, 2*pi);
\draw[->] (0,0) -- (2*pi,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$y$};
\draw[color=blue]   plot (\x,{sin(\x r)});
\node[below left, red] at (0, -1.2) {HERE};

% Second plot
\begin{scope}[rotate around={-90:(0,0)},shift={(1.2cm,0)}]
\draw[very thin,color=gray] (0, 2*pi);
\draw[->] (0,0) -- (2*pi,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$y$};
\draw[color=blue]   plot (\x,{cos(\x r)});
\end{scope}

\coordinate (upperright) at (7,2);
\coordinate (lowerleft) at (current bounding box.south west);
\pgfresetboundingbox
\useasboundingbox (upperright) rectangle (lowerleft);

\draw (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
\end{document}


A similar result can be obtained by switching the x- and y-coordinates in the plot, and changing the drawing of the axis. Some bounding box juggling was required here as well.

\documentclass[12pt,border=2mm]{standalone}
\usepackage{tikz}

\begin{document}

%% First plot
\begin{tikzpicture}[scale=1.5, domain=0:2*pi]
\draw[very thin,color=gray] (0, 2*pi);
\draw[->] (0,0) -- (2*pi,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$y$};
\draw[color=blue]   plot (\x,{sin(\x r)});
\node[below left, red] at (0, -1.2) {HERE};

% Second plot
\begin{scope}[yshift=-1.2cm]
\draw[very thin,color=gray] (-2*pi,0);
\draw[->] (0,0) -- (0,-2*pi) node[right] {$x$};
\draw[->] (-1.2,0) -- (1.2,0) node[above] {$y$};
\draw[color=blue]   plot ({cos(\x r)},-\x);
\end{scope}

\coordinate (upperleft) at (-1.5,2);
\coordinate (lowerright) at (current bounding box.south east);
\pgfresetboundingbox
\useasboundingbox (upperleft) rectangle (lowerright);

\draw (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
\end{document}

-

Not an answer to the direct question but a simple illustration for mapping sine/cosine values using sin and cos paths.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}

\foreach \x in {-pi/2,0,pi/2}{
\draw[dashed,red!30] (\x,0) -- ++(0,2*pi);
\draw[dashed,red!30] (0,-\x) -- ++(-2*pi,0);
}

\draw (0,0) circle (pi/2);
\begin{scope}[shift={(-pi/2,1.5*pi)}]
\draw (0,0) node[left] {0}-- (pi,0) (0,1) node[left] {1};
\draw[ultra thick,blue] (pi,1) cos (pi/2,0) sin (0,-1) node[left] {-1} ;
\end{scope}

\begin{scope}[rotate=-90,shift={(-pi/2,-1.5*pi)}]
\draw (0,0) node[above] {0}-- (pi,0) (0,-1) node[above] {-1};
\draw[ultra thick,blue] (0,1) node[above] {1} cos (pi/2,0) sin (pi,-1);
\end{scope}

\end{tikzpicture}
\end{document}


I don't know the actual intention but it can be furnished by putting arbitrary points on the circle and lines can be extended to intersect the curves etc.

-