# How to put a label to a /draw plot command in TikZ correctly?

I want to draw some interpolation curves and came across the following command

\draw plot[smooth] coordinates {(1,1) (4,8) (6,3) (8,9)};


That seems quite nice. Now I wanted to add some labels and found some information here (Labeling a function's plot generated by “plot function”) and here (How to label a path drawn using tikz with \draw plot?)

Now my solution looks like:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[label/.style={postaction={decorate,
transform shape,
decoration={markings,mark=at position 0.5 with \node #1;}}}]
\draw[help lines] (0,0) grid (10,10);
\draw[->,label={[above]{1}}] plot[smooth] coordinates {(1,1) (4,8) (6,3) (8,9)};
\end{tikzpicture}
\end{document}


Everything seems to work, but at one point I get an error I can't understand or solve. If I change mark=at position to a value less than 0.4 it still produces the desired output, but gives me the following error messange.

! Dimension too large.
\relax
l.10 ...th] coordinates {(1,1) (4,8) (6,3) (8,9)};

! Dimension too large.

l.10 ...th] coordinates {(1,1) (4,8) (6,3) (8,9)};

! Dimension too large.
\relax
l.10 ...th] coordinates {(1,1) (4,8) (6,3) (8,9)};


Any ideas what's going on there or how to solve it? Thanks a lot.

• If you are looking for plotting alternatives, how about package pgfplots? – Johannes_B Mar 3 '14 at 15:20
• BTW; Your example runs fine on my machine, maybe you jusst need an update. You can list all used files by putting \listfiles in your very first line, and have a look into the log file afterwards. The recent version of tikz/pgf is 3.0 – Johannes_B Mar 3 '14 at 15:23
• It compiles fine on my machine too (also for pos=0.9). – Claudio Fiandrino Mar 3 '14 at 15:23
• @ClaudioFiandrino: Does it also compile for pos=0.2? – stephan boehme Mar 3 '14 at 15:51
• @Johannes_B: I updated to version 3.0, but there is still the error when compiling with pos=0.2 – stephan boehme Mar 3 '14 at 16:28

The conflict between smooth and decorations has already appeared here; the most recent example is Add arrows to a smooth tikz function. In your concrete case, a work-around to prevent the "Dimension too large" error allowing you to still use smooth, is to use pre length=1pt, post length=1pt in the decoration. For the example below I changed to a style with two argument so as to be able to control the location of the decoration, but you can use your original settings:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[
label/.style 2 args={
postaction={
decorate,
transform shape,
decoration={
pre length=1pt, post length=1pt,
markings,
mark=at position #1 with \node #2;
}
}
}
]
\draw[help lines] (0,0) grid (10,10);
\draw[->] plot[smooth] coordinates {(1,1) (4,8) (6,3) (8,9)} [
label={0}{[above]{1}},
label={0.05}{[above]{1}},
label={0.1}{[above]{1}},
label={0.15}{[above]{1}},
label={0.2}{[above]{1}},
label={1.25}{[above]{1}}
];
\end{tikzpicture}
\end{document}