Search code examples
pythondiagramflowchart

How can i create a tree like diagram from a file?


I have a file composed of links between objects:

object1 obj

Solution

  • You can use networkx for this. What you have is a a file of 'links' which in networkx are called 'edges'. In your case you can make use of the read_adjlist function.

    import networkx as nx
    g = nx.read_adjlist('yourfile')
    

    You can then print the graph using libs like matplotlib or graphviz

    import matplotlib.pyplot as plt
    nx.draw(g)
    plt.draw
    plt.show()
    

    If you want your graph to be prettier or have a specific layouts have fun trying out graphviz, sadly I'm super bad at it so you'll have to dig it by yourself ;)