Annimation of Pyvis graphs

598 Views Asked by At

I am just learning Pyvis, I wonder if there is a way I can generate animated graphs. So far, I can only do the following:

  • define the graph
  • add nodes and edges to it
  • show it or save it

my question is: is there a way to -instead of re-creating the entire html file- only updating components of the previous generated HTML file.

here is my code so far:

from pyvis.network import Network

labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
l1, l2, l3, l4, l5, l6, l7 = labels
edgelist= [(l1,l2),(l2,l3), (l3,l4), (l3,l5), (l4, l1), (l5, l6), (l5, l7)]

xs = [-400, -400,  -200,  0,  0,    200, 200] 
ys = [ -200,  -100,  -100,   -200,  0,   -100,  100]

#g = Network('1000px', '1000px')  #that is from -500 to 500
g = Network(height='750px', width='100%', bgcolor='#222222', font_color='white')

g.add_nodes(labels,
            value=[1, 1, 1, 1, 1, 1, 1], #size
            title=labels,
            x=xs,
            y=ys,
            label=labels)
for n in g.nodes:
    n.update({'physics': False})
    n.update(shape='circle')  
g.toggle_drag_nodes(False)

g.add_edges(edgelist)
for i, e in enumerate(g.edges):
    e.update(value=i)
    e.update(label=str(i))

g.show('p.html')
#g.save_graph('p.html')
0

There are 0 best solutions below