File: plot_write_dotfile.py

package info (click to toggle)
networkx 2.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,764 kB
  • sloc: python: 78,797; makefile: 141; javascript: 120
file content (23 lines) | stat: -rw-r--r-- 566 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
=============
Write Dotfile
=============


Write a dot file from a networkx graph for further processing with graphviz.

You need to have either pygraphviz or pydot for this example.

See https://networkx.github.io/documentation/latest/reference/drawing.html
"""

import networkx as nx

# This example needs Graphviz and either PyGraphviz or pydot.
# from networkx.drawing.nx_pydot import write_dot
from networkx.drawing.nx_agraph import write_dot


G = nx.grid_2d_graph(5, 5)  # 5x5 grid
write_dot(G, "grid.dot")
print("Now run: neato -Tps grid.dot >grid.ps")