PyGraphviz
Description:
- PyGraphviz is a Python interface to the Graphviz graph layout and visualization package. With PyGraphviz you can create, edit, read, write, and draw graphs using Python to access the Graphviz graph data structure and layout algorithms.
Resources:
- [GitHub] https://github.com/pygraphviz/pygraphviz
- [Examples] https://github.com/pygraphviz/pygraphviz/tree/main/examples
- [Docs] https://pygraphviz.github.io/
Example 1
Section titled “Example 1”Create a simple example to create a graphviz dot file and draw a graph.
import pygraphviz as pgvfrom pathlib import Pathfrom IPython.display import Image
tmp = "/tmp/demo_notebooks"Path(tmp).mkdir(exist_ok=True)
A = pgv.AGraph()
A.add_edge(1, 2)A.add_edge(2, 3)A.add_edge(1, 3)
print(A.string()) # print to screenA.write(f"{tmp}/simple.dot") # write to simple.dot
B = pgv.AGraph(f"{tmp}/simple.dot") # create a new graph from fileB.layout() # layout with default (neato)B.draw(f"{tmp}/simple.png") # draw png (the format follows the file extension)Image(filename=f"{tmp}/simple.png") # show the PNG in the notebookstrict graph "" { 1 -- 2; 1 -- 3; 2 -- 3;}
ganymede is made by Eugo