!pip install graphviz
from graphviz import Graph
G=Digraph(format="png")
G.attr("node", fontname="Meiryo UI", fontsize='9', shape="circle")
G.attr(overlap='false', splines='true')
# Create Cluster
with G.subgraph(name='cluster_root')asc:
c.attr(color='white', label='2022')
#2022-01-06
with c.subgraph(name='cluster01-06') as c0106:
c0106.attr(color='red', label='01-06')
for node0106 in range (1092,1103):
c0106.node(str(node0106))
#2022-01-07
with c.subgraph(name='cluster01-07') as c0107:
c0107.attr(color='blue', label='01-07')
for node0107 in range (1103,1134):
c0107.node(str(node0107))
c0107edges = [(1103,1104), (1103,1105), (1103,1106), (1092,1119), (1092,1120),
(1092,1121),(1092,1122),(1092,1124),(1099,1124),(1101,1125),
(1101,1126),(1102,1127)]
for i, jinc0107edges:
c0107.edge(str(i), str(j), color="#00000080")
#2022-01-08
with c.subgraph(name='cluster01-08') as c0108:
c0108.attr(color='yellow', label='01-08')
for node0108 in range (1134, 1184):
c0108.node(str(node0108))
c0108edges=[(1139, 1140), (1139, 1141), (1148, 1149), (1113, 1151), (1110, 1152),
(1088,1153),(1117,1154),(1107,1155),
(1103,1157),(1103,1158),(1103,1159),(1103,1160),(1103,1161),
(1103,1162),(1103,1163),(1103,1164),(1103,1165),
(1118,1166),(1118,1167),(1123,1168),(1115,1169),(1128,1170),
(1128,1171),
(1117,1174),(1117,1175),(1117,1176),(1117,1177),(1117,1178),
(1117,1179),(1117,1180),(1117,1181)]
for i, jinc0108edges:
c0108.edge(str(i), str(j), color="#00000080")
display(G)
I want to save the picture displayed in display(G) to an image file such as png.
G.view(filename='digraph')
I want to delete nodes with no edges at the end
Adding the previous G.view(filename='digraph')
creates a file named digraph
(source code in dot
language) in the running directory. If the gvpr
command is installed, delete the node without an edge below and create a PNG-format file.
$gvpr-c'N[$.degre==0]{delete(NULL,$)}'digraph | dot-Tpng-odigraph.png
© 2024 OneMinuteCode. All rights reserved.