Skip to content

RandomGraphSource

vtk-examples/Python/Graphs/RandomGraphSource


Other languages

See (Cxx), (Java)

Question

If you have a question about this example, please use the VTK Discourse Forum

Code

RandomGraphSource.py

#!/usr/bin/env python
import vtk


def main():
    randomGraphSource = vtk.vtkRandomGraphSource()
    randomGraphSource.SetNumberOfVertices(5)
    randomGraphSource.SetNumberOfEdges(4)
    # This ensures repeatable results for testing. Turn this off for real use.
    randomGraphSource.SetSeed(0)
    randomGraphSource.Update()

    graphLayoutView = vtk.vtkGraphLayoutView()
    graphLayoutView.AddRepresentationFromInput(randomGraphSource.GetOutput())
    graphLayoutView.ResetCamera()
    graphLayoutView.Render()
    graphLayoutView.GetInteractor().Start()


if __name__ == '__main__':
    main()