> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# PyGraphviz

> PyGraphviz is a Python interface to the Graphviz graph layout and visualization package.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/data_visualization/graphviz/pygraphviz/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/data_visualization/graphviz/pygraphviz/pygraphviz.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/data_visualization/graphviz/pygraphviz.ipynb)

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

Create a simple example to create a graphviz dot file and draw a graph.

```python
import pygraphviz as pgv
from pathlib import Path
from 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 screen
A.write(f"{tmp}/simple.dot")  # write to simple.dot

B = pgv.AGraph(f"{tmp}/simple.dot")  # create a new graph from file
B.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 notebook
```

```text title="Output"
strict graph "" {
	1 -- 2;
	1 -- 3;
	2 -- 3;
}
```

<figure class="gn-output"><img src="https://eugo.io/docs/ganymede/demo_notebooks/data_visualization/graphviz/pygraphviz/output-3-2.png" width="179" height="142" alt="Figure drawn by code cell 1" loading="lazy" decoding="async"></figure>
