"""Visualize a 2D/3D network and its properties""" # (see also example: lineage_graph.py) from vedo import Points, show, sin from vedo.pyplot import DirectedGraph # Create some graph with nodes and edges # layouts: [2d, fast2d, clustering2d, circular, circular3d, cone, force, tree] g = DirectedGraph(layout='fast2d') for i in range(6): g.addChild(i) # add one child node to node i for i in range(3): g.addChild(i) for i in range(3): g.addChild(i) for i in range(7, 9): g.addChild(i) for i in range(3): g.addChild(12) # add 3 children to node 12 g.build() dgraph = g.unpack(0).lineWidth(4) # get the graph lines nodes = dgraph.points() # get the 3d points of the nodes pts = Points(nodes, r=12).c('red').alpha(0.5) v1 = ['node' + str(n) for n in range(len(nodes))] v2 = [sin(x) for x in range(len(nodes))] labs1 = pts.labels(v1, scale=.04, italic=True).addPos(.05, 0.04, 0).c('green') labs2 = pts.labels(v2, scale=.04, precision=3).addPos(.05, -.04, 0).c('red') # Interpolate the node value to color the edges:
"""Visualize a 2D/3D network and its properties""" # (see also example: lineage_graph.py) from vedo import Points, show, sin from vedo.pyplot import DirectedGraph # Create some graph with nodes and edges # layouts: [2d, fast2d, clustering2d, circular, circular3d, cone, force, tree] g = DirectedGraph(layout='fast2d') ##################### Use networkx to create random nodes and edges # import networkx # G = networkx.gnm_random_graph(n=20, m=35) # for i, j in G.edges(): g.addEdge(j,i) ##################### Manually create nodes and edges for i in range(6): g.addChild(i) # add one child node to node i for i in range(3): g.addChild(i) for i in range(3): g.addChild(i) for i in range(7,9): g.addChild(i) for i in range(3): g.addChild(12) # add 3 children to node 12 g.addEdge(1,16) ##################### build and draw graph = g.build().unpack(0).lineWidth(4) # get the vedo 3d graph lines nodes = graph.points() # get the 3d points of the nodes pts = Points(nodes, r=10).lighting('off') v1 = ['node'+str(n) for n in range(len(nodes))] v2 = [sin(x) for x in range(len(nodes))] labs1 = pts.labels(v1, scale=.04, italic=True).addPos(.05,0.04,0).c('green')
""" # N.B.: no positions are specified here, only connectivity! from vedo import show, settings from vedo.pyplot import DirectedGraph settings.allowSubScripts = 0 # Layouts: [2d, fast2d, clustering2d, circular, circular3d, cone, force, tree] #g = Graph(layout='2d', zrange=7) g = DirectedGraph(layout='cone') #g = DirectedGraph(layout='circular3d', height=1, radius=1.5) #g = DirectedGraph(layout='force') # Vertex generation is automatic, # add a child to vertex0, so that now vertex1 exists g.addChild(0, edgeLabel="Mother giving birth\nto her little baby cell") g.addChild(1) g.addChild(1) g.addChild(2) g.addChild(2) g.addChild(2) g.addChild(3) g.addChild(3, edgeLabel="It's a male!") g.addChild(4) g.addChild(4) for i in range(7): g.addChild(5, vertexLabel="cell5_" + str(i)) g.addChild(7) g.addChild(7) g.addChild(7)