# Creating a graph in VTK using ConstructGraph

**URL:** https://discourse.vtk.org/t/creating-a-graph-in-vtk-using-constructgraph/3157
**Category:** Support
**Created:** [April 25, 2020, 12:39pm UTC](https://discourse.vtk.org/t/creating-a-graph-in-vtk-using-constructgraph/3157 "2020-04-25T12:39:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Deepa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/deepa/32/1680_2.png) [@Deepa](https://discourse.vtk.org/u/Deepa)
#### Post date: [April 25, 2020, 12:39pm UTC](https://discourse.vtk.org/t/creating-a-graph-in-vtk-using-constructgraph/3157/1 "2020-04-25T12:39:08Z")

</div>

I want to create a graph using VTK class [https://lorensen.github.io/VTKExamples/site/Python/Graphs/ConstructGraph/](https://lorensen.github.io/VTKExamples/site/Python/Graphs/ConstructGraph/)

```
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()

```

is the function defined. But I not quite sure how to use this.

For instance, in networkx I would do  
t = [0, 2, 4, 5, 6, 8, 9, 11, 13, 1, 10, 1, 3, 7]  
h= [1, 3, 3, 1, 7, 7, 10, 12, 12, 14, 14, 12, 14, 10]  
ed\_ls = [(x, y) for x, y in zip(tail, head)]  
G = nx.OrderedGraph()  
G.add\_edges\_from(ed\_ls)  
nx.draw(G)

Suggestions on how to create the same graph in VTK will be helpful
