ATLAS Offline Software
Loading...
Searching...
No Matches
dot.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3# write out a Digraph in dot format
4
5def dot(G, fn, nodesToHighlight=[]):
6 """dot() is a function to output a graph which suppords adj() that writes
7 out a .dot file for graph visualisation"""
8
9 lines = [
10 "digraph G{\n",
11 "layout=twopi ranksep=3 ratio=auto\n"]
12
13 for v in range(G.V):
14
15 for w in G.adj(v):
16 line = '%d -> %d;' % (v, w)
17 lines.append(line)
18
19 for v in nodesToHighlight:
20 assert v < G.V
21 lines.append('%d [color=red, style=filled];' % v)
22
23 lines.append('}\n')
24
25 text = '\n'.join(lines)
26
27 with open(fn, 'w') as fh:
28 fh.write(text)
29
Definition dot.py:1