# How to color some areas of a branching diagram

do you have an idea how could I reproduce the brancing-diagram in this picture? I suppose that it was made with tikz or pst-tree but I don't know how, especially how to get those coloured areas.

The tree in the picture is taken from this presentation

MWE (produces almost the same tree but not the coloured areas):

\documentclass[11pt]{standalone}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing,trees}

\begin{document}

\vspace{5cm}
\tikzstyle{level 1}=[level distance=3cm, sibling distance=3cm,very thick]
\tikzstyle{level 2}=[level distance=3cm, sibling distance=2cm]
\tikzstyle{level 3}=[level distance=3cm, sibling distance=1.5cm]

\tikzstyle{empty node} = [circle,draw,minimum width=1pt,fill=white,inner sep=2pt]
\tikzstyle{end} = [circle,draw,inner sep=1.2,fill=black, minimum width=2pt]

\begin{tikzpicture}[grow=right, sloped]
\node[end] {}
child[loosely dotted] {
node[end] {}
child{
node[end]{}
child{
node[end] {}
}
child{
node[end] {}
}
}
child {
node[end] {}
child{
node[end] {}
}
child{
node[end] {}
}
}
}
child[loosely dotted]{
node[end]{}
child{
node[end] {}
}
child{
node[end] {}
}
}
child {
node[empty node,label=above:{\Large{\textit{i}$_c$}}] {}
child[loosely dashed] {
node[end] {}
child{
node[end]{}
child{
node[end]{}
}
child{
node[end]{}
}
}
}
child[dashed]{
node[end] {}
child{
node[end]{}
child{
node[end]{}
}
child{
node[end]{}
}
}
}
}
;
\end{tikzpicture}
\end{document}


Thank you very much in advance!!!

• What did you try sofar. Please add a MWE (starting with \documentclass and ending with \end{document}) – albert Jun 6 '18 at 18:05
• Drawing the tree is easy. I would recommend using forest. Drawing the coloured regions can be done with the TikZ fit library. Getting the exact shapes might involve some work. Perhaps you should try that and post your code here when you get stuck. – Alan Munn Jun 6 '18 at 18:24
• @AlanMunn Thanks! I'll try the fit library. I've added a MWE example which produces the tree using tikz, but perhaps it is even easier with forest. – Tonio Jun 6 '18 at 18:47
• You can have a look to Hobby path realization in convex hull approach for an automatic solution. – Claudio Fiandrino Jun 6 '18 at 19:55
• There's at least one very similar question to this somewhere. Specific to Forest, possibly. Certainly with Forest solutions. – cfr Jun 6 '18 at 22:45

## 1 Answer

Your code doesn't produce a tree with the structure shown, at least when I compile it, and it isn't clear how to apply the shading to your tree. So, I adapted it to produce the illustrated structure, after translating it to Forest. The backgrounds library is used for the shadings. Most of the packages and libraries you list in your code are egregious.

\documentclass[border=10pt,11pt]{standalone}
\usepackage{forest}
\usetikzlibrary{backgrounds}
\begin{document}
\tikzset{% \tikzstyle is deprecated
empty node/.style = {circle,draw,minimum width=1pt,fill=white,inner sep=2pt},
end/.style = {circle,draw,inner sep=1.2,fill=black, minimum width=2pt,},
}%
\begin{forest}
for tree={
grow=0,
edge+={loosely dotted, very thick},
end,
s sep'=5mm,
fit=band,
},
where level<=1{calign=fixed edge angles}{},
before drawing tree={
tempdima/.max={x}{tree},
where n children=0{x/.register=tempdima}{},
}
[
[
[[[][]][[][]]]
[[[][]][[][]]]
]
[
[
[[][]][[][]]
]
[
[[][]][[][]]
]
[, for current and ancestors={edge+={solid}}, empty node, very thick, label=above:{\Large{\textit{i}$_c$}}
[, for tree={edge+={loosely dashed}} [[][]]]
[, for tree={edge+={dashed}} [[][]]]
]
]
]
\begin{scope}[on background layer]
\begin{scope}[transparency group, opacity=.25]
\draw [blue, line width=30pt, line cap=round] (!r) -- (!rll);
\node [fit=(!rlll) (!rll1) (!rlllll) (!rll111), fill=green, rounded corners] {};
\path [fill, draw, magenta, line width=20pt, rounded corners] (!r1.center) -- (!r111.center) -- (!rF.center) -- (!rl2L.center) -- (!rl2l.center) -- (!rl2.center) -- cycle;
\end{scope}
\end{scope}
\end{forest}
\end{document}


• +1 Very nice way to do the colouring. You're missing a solid edge on the top branch from the root. – Alan Munn Jun 7 '18 at 0:15
• Thanks. @AlanMunn Left as an exercise for the reader? – cfr Jun 7 '18 at 0:21
• @AlanMunn Better now? – cfr Jun 7 '18 at 0:24
• Perfect........ :) – Alan Munn Jun 7 '18 at 0:25
• @AlanMunn I got rid of a, too. Seemed excessive. – cfr Jun 7 '18 at 0:25