# combining two diagrams with tikz and scale judiciously

I have the following code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc}

\begin{document}
\usetikzlibrary{decorations.pathmorphing,calc}
\begin{tikzpicture}
% Define some reference points
% The figure is drawn a bit bigger, and then clipped to the following dimensions:
\coordinate (clipping area) at (10, 7);
\clip (0,0) rectangle (clipping area);

% Next reference points are relative to the lower left corner of the clipping area
\coordinate (water level) at (0, 6);
\coordinate (bottom)      at (5, 1.3);     % (bottom of the pit)
\coordinate (ground1)     at (0, 5);       % (left shore)
\coordinate (ground2)     at (10, 5);      % (right shore)

% Coordinates of the bigger area really drawn
\coordinate (lower left)  at ([xshift=-5mm, yshift=-5mm] 0,0);
\coordinate (upper right) at ([xshift=5mm,  yshift=5mm] clipping area);

% Draw the water and ripples
\draw [draw=blue!80!black, decoration={bumps, mirror, segment length=6mm}, decorate,
bottom color=cyan!60!black, top color=blue!20!white]
(lower left) rectangle (water level-|upper right);

% draw horizontal dashed line
\draw[dashed](0,4) -- (10,4);
\draw[dashed](0,3.6) -- (10,3.6);

% Draw the ground
\draw [draw=brown!30!black, fill=brown]
(lower left) -- (lower left|-ground1)  --
(ground1) .. controls ($(ground1)!.3!(bottom)$) and (bottom-|ground1) ..
(bottom) .. controls (bottom-|ground2) and ($(ground2)!.3!(bottom)$) ..
(ground2) -- (ground2-|upper right) -- (lower left-|upper right) -- cycle;

\end{tikzpicture}
\end{document}


which generates the left hand diagram of the figure below:

My next task is to generate the right hand diagram and scale it so that the horizontal lines match on both figures (shown as a rectangular region in second figure). The main problem I have with generating this is that the first diagram is cropped and I fail to find a consistent way of scaling the second diagram. The second diagram shown is a simple example. The actual diagram I wish to insert is given by the following code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc}

\begin{document}
\begin{tikzpicture}
[x = 2mm, y = 7mm,transition/.style = {rectangle, draw = black!50}] % define rectangular region
\draw [>=stealth, ->,thick](0,0) -- (0,-10); % draw xaxis for the diagram
\draw [>=stealth, ->,thick](0,0) -- (42,0); % draw yaxis
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} % temperatures for graph
\draw[transition] (0,-6) rectangle (40,-2); % draw the rectangular region
\draw [thick] (0,-4) -- (41,-4); % define the thermocline
\draw[dashed] (4,0) -- (4,-10); % draw line at 4 degC
\draw (4,-10) .. controls (4,-4)  and (18,-4) .. (18,0); % draw temperature profile i.e. curved line
\end{tikzpicture}
\end{document}

-
But the code you included for the second figure does not have the tow horizontal dashed lines. Could you please complete the code and add them? –  JLDiaz Mar 4 '13 at 11:46
Sorry, the two horizontal lines correspond to the rectangular region in the second figure. Hope this makes sense. –  KatyB Mar 4 '13 at 11:48

The easiest solution is to use the same y-scale in both figures, and also use the same coordinate system in both. I mean, since in the first one the water level is at y=6, the second one should use a y-axis of 6 units in lenght, and all other y-coordinates should be adjusted accordingly. The fact that the first figure uses positive y, while the second one uses negative y complicates things a bit, but it can be done:

\documentclass{article}
\usepackage{tikz}
%\usepackage{tikzscale}
\usetikzlibrary{decorations.pathmorphing,calc}

\begin{document}
\usetikzlibrary{decorations.pathmorphing,calc}
\begin{tikzpicture}[y=15mm, x=8mm]
% Define some reference points
% The figure is drawn a bit bigger, and then clipped to the following dimensions:
\coordinate (clipping area) at (10, 7);
\clip (0,0) rectangle (clipping area);

% Next reference points are relative to the lower left corner of the clipping area
\coordinate (water level) at (0, 6);
\coordinate (bottom)      at (5, 1.3);     % (bottom of the pit)
\coordinate (ground1)     at (0, 5);       % (left shore)
\coordinate (ground2)     at (10, 5);      % (right shore)

% Coordinates of the bigger area really drawn
\coordinate (lower left)  at ([xshift=-5mm, yshift=-5mm] 0,0);
\coordinate (upper right) at ([xshift=5mm,  yshift=5mm] clipping area);

% Draw the water and ripples
\draw [draw=blue!80!black, decoration={bumps, mirror, segment length=6mm}, decorate,
bottom color=cyan!60!black, top color=blue!20!white]
(lower left) rectangle (water level-|upper right);

% draw horizontal dashed line
\draw[dashed](0,4) -- (10,4);
\draw[dashed](0,3.6) -- (10,3.6);

% Draw the ground
\draw [draw=brown!30!black, fill=brown]
(lower left) -- (lower left|-ground1)  --
(ground1) .. controls ($(ground1)!.3!(bottom)$) and (bottom-|ground1) ..
(bottom) .. controls (bottom-|ground2) and ($(ground2)!.3!(bottom)$) ..
(ground2) -- (ground2-|upper right) -- (lower left-|upper right) -- cycle;

\end{tikzpicture}
% Important: no blank lines here
\begin{tikzpicture}
[x = 1.5mm, y = 15mm,transition/.style = {rectangle, draw = black!50}] % define rectangular region
\draw [>=stealth, ->,thick](0,0) -- (0,-6); % draw xaxis for the diagram
\draw [>=stealth, ->,thick](0,0) -- (42,0); % draw yaxis
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} % temperatures for graph
\draw[transition] (0,-2) rectangle +(40,-0.4); % draw the rectangular region
\draw [thick] (0,-2.2) -- (41,-2.2); % define the thermocline
\draw[dashed] (4,0) -- (4,-6); % draw line at 4 degC
\draw (4,-6) .. controls (4,-2)  and (18,-2) .. (18,0); % draw temperature profile i.e. curved line
\end{tikzpicture}
\end{document}


You can play with the x-scale in each, so that both fit in the same line at the aspect-ratio you like the most.

-
One problem with this is that if I place it into a figure environment they do not lie side by side, the second figure will be placed underneath the first, no matter what size I scale them –  KatyB Mar 5 '13 at 8:17
@kate Be sure not to insert a blank line between pictures (since that will make a new paragraph for the second one). You can even put a % rigth after the first \end{tikzpicture}, so that the end-of-line is not seen by tex (that would produce a space separating both pictures, and it will be a valid break point for the line if it was too long). –  JLDiaz Mar 5 '13 at 8:32