# tikz - specifying more controls on curved lines

Im drawing a temperature profile for a given body of water:

\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] {Depth [m]};
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] {Temperature [$^{o}$C]};
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};}
\foreach \y in {0,-5,-10,-15,-20} { \draw(-2mm,\y)--(2mm,\y) node[left]{\y};}
\draw (6,-20) .. controls (6,-4)  and (17,-6) .. (17.5,0);
\end{tikzpicture}


From here I would like to copy the profile i.e. the curved line where the temperature at depth is increased as +2 degC and -2degC but where the surface of the water remains the same. For example:

\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] {Depth [m]};
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] {Temperature [$^{o}$C]};
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};}
\foreach \y in {0,-5,-10,-15,-20} { \draw(-2mm,\y)--(2mm,\y) node[left]{\y};}
\draw (6,-20) .. controls (6,-4)  and (17,-6) .. (17.5,0);
\draw[dashed,red](8,-20) .. controls (8,-4)  and (17,-6) .. (17.5,0);
\draw[dashed,blue] (4,-20) .. controls (4,-4)  and (17,-6) .. (17.5,0);
\end{tikzpicture}


This will generate two additional curved lines, the problem here is that the temperatures do not differ by the amount specified all the way down the profile i.e. the difference between the lines are 2degC at the bottom but up to a depth of 10 m they linearly increase to 2degC. I realise this problem is probably due to the number of control points used, but I can't seem to solve the problem.

amended: working example

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc,shapes,arrows,snakes,shapes.geometric,patterns}

\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] {Depth [m]}; % draw xaxis for the diagram
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] {Temperature [$^{o}$C]}; % draw yaxis
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} % temperatures for graph
\foreach \y in {0,-5,-10,-15,-20} { \draw(-2mm,\y)--(2mm,\y) node[left]{\y};} % depth for graph

\draw (6,-20) .. controls (6,-4)  and (17,-6) .. (17.5,0); % draw temperature profile i.e. curved line
\draw[dashed,red](8,-20) .. controls (8,-4)  and (17,-6) .. (17.5,0); % temp profile = 1degC
\draw[dashed,blue] (4,-20) .. controls (4,-4)  and (17,-6) .. (17.5,0); % draw new temperature profile
\end{tikzpicture}
\end{figure}
\end{document}


producing:

From here, you can see that at the lowe depths the difference between the curves lines is not as specified. I would like to generate the graph where the three lines are the same at depth = 0m but thereafter they vary by 2degC. How could I do this?

-
Could you post a minimal working example (MWE), including packages and \documentclass. Also, it would help if you posted a screenshot indicating what is wrong as it's not completely clear to me from your description. Are the 17 and 17.5s at the ends of your curves typos? Should the red dashed curve end at 15.5 and the blue one at 19.5? If so, your lines are always separated by 2 degrees horizontally so I'm not sure what you're looking for. –  Loop Space Feb 26 '13 at 13:53
"but thereafter they vary by 2degC". Presumably there is some allowance for them to get from being together to the 2degC separation. At the moment that change happens gradually over the length of the curve. By what depth do you want them to be 2degC apart? –  Loop Space Feb 26 '13 at 14:23
Sorry I'm not being very clear here. So, I would like to generate the figure that I have shown but instead of having the 2 degree difference between the lines taking 20 m to occur I would like this to happen at say 2 m. –  KatyB Feb 26 '13 at 14:26
There's easy ways and complicated ways to do this. How crucial are the numbers in specifying your curve? –  Loop Space Feb 26 '13 at 15:05

The "easy" way of doing this is to do it by eye. Picking a reasonable guess and then messing around with it until it "looks right" is simpler for one-off situations where being absolutely precise isn't important. What I've done here is to effectively split the curved path at the -2m depth point, then copied the lower parts in the dashed patterns and curved the tops to look okay.

I would recommend using relative control points as it makes adjusting things much easier since then the control points move as you move the end points.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/99999/86}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] {Depth [m]};
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] {Temperature [$^{o}$C]};
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};}
\foreach \y in {0,-5,-10,-15,-20} { \draw(-2mm,\y)--(2mm,\y) node[left]{\y};}
\draw[ultra thick,cyan] (6,-20) .. controls (6,-4)  and (17,-6) .. (17.5,0);
\draw (6,-20) .. controls (6,-6.3)  and (14,-6) .. (16.8,-2) .. controls +(.28,.4) and +(.05,-.6) .. (17.5,0) coordinate (a);
\draw[dashed,red,xshift=2cm] (6,-20) .. controls (6,-6.3)  and (14,-6) .. (16.8,-2) .. controls +(1.12,1.6) and +(.05,-.6) .. (a);
\draw[dashed,blue,xshift=-2cm] (6,-20) .. controls (6,-6.3)  and (14,-6) .. (16.8,-2) .. controls +(1.12,1.6) and +(.05,-.6) .. (a);

\end{tikzpicture}
\end{document}


I've left the original line there in cyan to show that the split line is pretty close to it.

-

Is this what you want?

I've found that the easiest way is to use the plot kewyword. In order to get the right coordinates, I drawn a grid on top of your curves.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway]
{Depth [m]}; % draw xaxis for the diagram
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway]
{Temperature [$^{o}$C]}; % draw yaxis
\foreach \x in {0,4,10,20} {
\draw(\x,-2mm)--(\x,2mm) node[above]{\x};} % temperatures for graph
\foreach \y in {0,-5,-10,-15,-20} {
\draw(-2mm,\y)--(2mm,\y) node[left]{\y};} % depth for graph

\draw[black] plot[smooth,tension=.2]
coordinates{(6,-20) (6.5,-15) (7,-13) (8,-10.6) (9,-9)
(10,-7.8) (12, -6) (14,-4.6) (15,-3.8) (16,-3) (17,-1.8) (17.5,0)};
\draw[red, dashed] plot[smooth, tension=.2] coordinates
{ (8,-20) (8.5,-15) (9,-13) (10,-10.6) (11,-9)
(12,-7.8) (14, -6) (16,-4) (17,-2.5) (17.5,0)};
\draw[blue, dashed] plot[smooth, tension=.2]
coordinates{(4,-20) (4.5,-15) (5,-13) (6,-10.6) (7,-9)
(8,-7.8) (10, -6) (12,-4.6) (13,-3.9) (14,-3.4) (15,-2.8)
(16,-2.3) (17, -1.4)    (17.5,0)
};
\end{tikzpicture}
\end{document}


Another solution, using ordinary bezier curves, but relative control points (and polar coordinates for the control points, relative to the extremes). Using this syntax I feel more easy to guess the result:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway]
{Depth [m]}; % draw xaxis for the diagram
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway]
{Temperature [$^{o}$C]}; % draw yaxis
\foreach \x in {0,4,10,20} {
\draw(\x,-2mm)--(\x,2mm) node[above]{\x};} % temperatures for graph
\foreach \y in {0,-5,-10,-15,-20} {
\draw(-2mm,\y)--(2mm,\y) node[left]{\y};} % depth for graph

\draw[black]        (6,-20) .. controls +(90:15) and +(-110:8) .. (17.5,0);
\draw[blue,dashed]  (4,-20) .. controls +(90:16) and +(-120:8) .. (17.5,0);
\draw[red,dashed]   (8,-20) .. controls +(90:14) and +(-95:7) .. (17.5,0);
\end{tikzpicture}
\end{document}


The curve is much more smooth this way. I prefer this result:

-
Wot no plot[hobby]? –  Loop Space Feb 26 '13 at 15:34
@AndrewStacey Heh. No, I leave that solution for you (for the interested reader, see here) –  JLDiaz Feb 26 '13 at 15:41