ConstructGraph
VTKEx/Python/Graphs/ConstructGraph
This example shows how to construct a simple graph.
Other languages
See (Cxx)
Question
If you have a simple question about this example contact us at VTKExProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum
Code¶
ConstructGraph.py
#!/usr/bin/env python
import vtk
def main():
g = vtk.vtkMutableUndirectedGraph()
v1 = g.AddVertex()
v2 = g.AddVertex()
g.AddEdge ( v1, v2 )
print ('Number of vertices:', g.GetNumberOfVertices())
print ("Number of edges:", g.GetNumberOfEdges())
g.AddEdge ( v1, v2 )
print ('Number of vertices:', g.GetNumberOfVertices())
print ('Number of edges:', g.GetNumberOfEdges())
graphLayoutView = vtk.vtkGraphLayoutView()
graphLayoutView.AddRepresentationFromInput(g)
graphLayoutView.ResetCamera()
graphLayoutView.Render()
graphLayoutView.GetInteractor().Start()
if __name__ == '__main__':
main()