1

When I run this code it's showing <IPython.core.display.Image object> but I need to save the file as png on my computer, how to do this

This is the code to create Unix Directory Structure Using Graphviz

    import pydot
    import os
    from IPython.display import Image, display

    rootdir = "/home/niranjan/Pictures/proj1"
    G = pydot.Dot(graph_type="digraph")
    for root, dirs, files in os.walk(rootdir):
        for subdir in dirs:
            node = pydot.Node(subdir,style="filled",fillcolor="green")
            G.add_node(node)
            edge = pydot.Edge(root.split("/")[-1],subdir)
            G.add_edge(edge)

    for file in files:
        node = pydot.Node(file,style="filled",fillcolor="yellow")
        G.add_node(node)
        edge = pydot.Edge(root.split("/")[-1],file)
        G.add_edge(edge)



    im = Image(G.create_png())
    display(im)
Pratap Alok Raj
  • 1,098
  • 10
  • 19

1 Answers1

1

You can use: G.write_png("file.png") You can also save the file as jpeg or other formats available.

hbstha123
  • 1,260
  • 11
  • 23