Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Preserving the rooted tree layout in graphs

I am working in a research project where I deal with rooted trees. I want to be able to add edges to the rooted tree and somehow "preserve" the rooted tree layout. More precisely, if I add the edges $(2,8)$ and $(3,6)$ in the rooted tree produced by the code below

G=Graph({0:[1,2,3,4],1:[5,6,7],4:[8,9,10],6:[11,12],9:[13,14]})
G.show(layout='tree',tree_root=0)
G.add_edges([(3,9),(2,6)])
G.show()

the layout of the updated graph is kind of messy and it gets worse if the order of the tree is increased. I want to add the new edges in a different color but without affecting the layout of the initial tree. Is this even possible?

Preserving the rooted tree layout in graphs

I am working in a research project where I deal with rooted trees. I want to be able to add edges to the rooted tree and somehow "preserve" the rooted tree layout. More precisely, if I add the edges $(2,8)$ and $(3,6)$ in the rooted tree produced by the code below

G=Graph({0:[1,2,3,4],1:[5,6,7],4:[8,9,10],6:[11,12],9:[13,14]})
G.show(layout='tree',tree_root=0)
G.add_edges([(3,9),(2,6)])
G.show()

the layout of the updated graph is kind of messy and it gets worse if the order of the tree is increased. I want to add the new edges in a different color but without affecting the layout of the initial tree. I want the updated graph to look like the output of this tikzpicture:

  \begin{tikzpicture}[
   V/.style = {% V as Vortex
        circle,thick,fill=orange},scale=0.4]


   %drawing nodes
    \node[V] (0) at (-9,11) [scale=0.5,draw] {0};
    \node[V] (1) at (-3,8) [scale=0.5,draw] {1};
    \node[V] (2) at (-7,8) [scale=0.5,draw] {2};
    \node[V] (3) at (-11,8)[scale=0.5,,draw] {3};
    \node[V] (4) at (-15,8) [scale=0.5,draw] {4};
    \node[V] (5) at (-1,5) [scale=0.5,draw] {5};
    \node[V] (6) at (-3,5) [scale=0.5,draw] {6};
    \node[V] (7) at (-5,5) [scale=0.5,draw] {7};
    \node[V] (8) at (-13,5) [scale=0.5,draw] {8};
    \node[V] (9) at (-15,5) [scale=0.5,draw] {9};
    \node[V] (10) at (-17,5) [scale=0.4,draw] {10};
    \node[V] (11) at (-2,2) [scale=0.4,draw] {11};
    \node[V] (12) at (-4,2) [scale=0.4,draw] {12};
    \node[V] (13) at (-14,2) [scale=0.4,draw] {13};
    \node[V] (14) at (-16,2) [scale=0.4,draw] {14};

    \draw[black,very thick]
    (0) to (1)
    (0) to (2)
    (0) to (3)
    (0) to (4)
    (1) to (5)
    (1) to (6)
    (1) to (7)
    (6) to (11)
    (6) to (12)
    (4) to (8)
    (4) to (9)
    (4) to (10)
    (9) to (13)
    (9) to (14);

     \draw[green,very thick,dotted]
     (3) to (9)
     (2) to (6);
\end{tikzpicture}

Is this even possible? possible?

Preserving the rooted tree layout in graphs

I am working in a research project where I deal with rooted trees. I want to be able to add edges to the rooted tree and somehow "preserve" the rooted tree layout. More precisely, if I add the edges $(2,8)$ and $(3,6)$ in the rooted tree produced by the code below

G=Graph({0:[1,2,3,4],1:[5,6,7],4:[8,9,10],6:[11,12],9:[13,14]})
G.show(layout='tree',tree_root=0)
G.add_edges([(3,9),(2,6)])
G.show()

the layout of the updated graph is kind of messy and it gets worse if the order of the tree is increased. I want to add the new edges in a different color but without affecting the layout of the initial tree. I want the updated graph to look like the output of this tikzpicture:

  \begin{tikzpicture}[
   V/.style = {% V as Vortex
        circle,thick,fill=orange},scale=0.4]


   %drawing nodes
    \node[V] (0) at (-9,11) [scale=0.5,draw] {0};
    \node[V] (1) at (-3,8) [scale=0.5,draw] {1};
    \node[V] (2) at (-7,8) [scale=0.5,draw] {2};
    \node[V] (3) at (-11,8)[scale=0.5,,draw] {3};
    \node[V] (4) at (-15,8) [scale=0.5,draw] {4};
    \node[V] (5) at (-1,5) [scale=0.5,draw] {5};
    \node[V] (6) at (-3,5) [scale=0.5,draw] {6};
    \node[V] (7) at (-5,5) [scale=0.5,draw] {7};
    \node[V] (8) at (-13,5) [scale=0.5,draw] {8};
    \node[V] (9) at (-15,5) [scale=0.5,draw] {9};
    \node[V] (10) at (-17,5) [scale=0.4,draw] {10};
    \node[V] (11) at (-2,2) [scale=0.4,draw] {11};
    \node[V] (12) at (-4,2) [scale=0.4,draw] {12};
    \node[V] (13) at (-14,2) [scale=0.4,draw] {13};
    \node[V] (14) at (-16,2) [scale=0.4,draw] {14};

    \draw[black,very thick]
    (0) to (1)
    (0) to (2)
    (0) to (3)
    (0) to (4)
    (1) to (5)
    (1) to (6)
    (1) to (7)
    (6) to (11)
    (6) to (12)
    (4) to (8)
    (4) to (9)
    (4) to (10)
    (9) to (13)
    (9) to (14);

     \draw[green,very thick,dotted]
     (3) to (9)
     (2) to (6);
\end{tikzpicture}

Is this even possible?