3

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.
<to be read again> 
                   \relax 
l.10 ...th] coordinates {(1,1) (4,8) (6,3) (8,9)};

! Dimension too large.
<recently read> \pgfmath@x 

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

! Dimension too large.
<to be read again> 
                   \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.

1 Answers1

2

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}

enter image description here

Gonzalo Medina
  • 505,128