I am trying to write some personal notes based on the notes for a course I took a long time ago. In these notes the professor had the following graphs:

enter image description here

enter image description here

enter image description here

These graphs are beautiful and made with scalable vector graphics. Moreover, they are representing basis functions for splines, which are a very recursive structure unless you go and implement the dynamic programming algorithm, which seems overkill for plotting a static image.

Any suggestion as to which packages or tools I can use to make this?

1 Answer 1


I do not really know why the title of the question carries "heavily recursive" but you can draw all of them easily with the standard TeX packages such as MetaPost, PSTricks and TikZ. Here is a TikZy version of your graphs.

\begin{tikzpicture}[font=\sffamily,transform shape,line cap=round]
  \draw[help lines] (-1,-1) grid (7,2);
  \draw[thick] (0,-1) -- (0,2) node[below left] {2};
  \draw[thick] (-1,0) -- (7,0) foreach \X in {1,...,7}
  { (\X,0) node [below left] {\X}};
  \foreach \Y [count=\X starting from 0] in {red,orange,green!60!black,cyan,brown!50!black,magenta}
  {\draw[line width=1mm,\Y] (\X,1)
     --node[black,above]{$\scriptstyle\mathsf{N}_{\mathsf{\X},\mathsf{1}}(u)$} (\X+1,1);}
  \foreach \Y [count=\X starting from 0] in {brown!50!black,red,orange,green!60!black,cyan} 
  {\draw[very thick,\Y] (\X,0) -- ++ (1,1) -- ++ (1,-1); }
  \draw[dashed,gray] foreach \X in {-1,5}
      {(\X,0) -- ++ (1,1) -- ++ (1,-1)};
  \draw[thick] (-0.1,0) -- (6.1,0) foreach \X in {0,...,6}
   { (\X,0) node [below] {\X}};  
  \foreach \Y [count=\X starting from 0] in 
  {\draw[very thick,\Y] plot[variable=\x,domain=-1.2:1.2,smooth] 
  ({0.5+\x+0.5*\X+ifthenelse(\X>2,2.5,0)},{gauss(\x)}); }
  \draw[thick] (-1,0) -- (7,0) foreach \X in {0,...,3}
   { ({-0.5+0.5*\X+ifthenelse(\X==3,0.5,0)},0) node [below] 
   foreach \Y [count=\X starting from 0] in {m,m+k-2,m+k-1,m+k}
   { ({5+0.5*\X-ifthenelse(\X==0,0.5,0)},0) node [anchor=north west,rotate=-45] 

enter image description here

  • It;s heavily recursive because high order splines are defined recursively from lower ones, but they also need a customly defined set of knot values, so it's quite annoying to code. An unoptimazed C++ implementation is about 50 lines.
    – Makogan
    Commented Dec 22, 2019 at 18:41
  • your example works for the easiest case which is splines of order 1, how would you go about plotting a recursive function? let;s say the fibonacci sequence (not to ask for splines because I know it'd be a pain)
    – Makogan
    Commented Dec 22, 2019 at 18:43
  • 1
    @Makogan TikZ is able to do recursions, and the Fibonacci numbers are actually used to demonstrate this in section 59 Math Library of pgfmanual v3.1.5. Also, aren't Bezier curves splines, i.e. the cubic Bezier curves that are implemented in all of these programs, aren't they cubic splines? They get used in the plot[smooth] coordinates {...} syntax, which provides us with a smooth interpolation of some coordinates.
    – user194703
    Commented Dec 22, 2019 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .