내 MultiDiGraph()
을 pydot
그래프로 변환하는 코드를 작성하여 자체 루프와 화살표를 표시했지만 전환 후 pydot
그래프 A
은 G
의 모든 속성을 손실했습니다. 그래프 A
의 노드 크기를 어떻게 바꿀 수 있으며, G
처럼 그 값을 node_sizes[]
목록의 해당 값과 동일하게 설정합니까?Pydot 그래프의 노드 크기를 변경할 수 있습니까?
코드 :
def draw_graph(graph, size):
# extract nodes from graph
nodes = set([n1 for n1, n2 in graph] + [n2 for n1, n2 in graph])
print("Nodes ",nodes,"\n")
node_sizes = []
for n in nodes:
#Scaling up the node importance by a factor of 2000 to make it visible
node_sizes.append(size[n] * 2000)
print("Node size ",node_sizes,"\n")
# create networkx graph
G=nx.MultiDiGraph()
G.add_edges_from(edges)
G.add_nodes_from(nodes)
edge_colours = ['black' for edge in G.edges()]
pos = nx.spring_layout(G)
nx.draw_networkx_nodes(G, pos, cmap=plt.get_cmap('jet'), node_size = node_sizes)
nx.draw_networkx_labels(G, pos)
nx.draw_networkx_edges(G, pos, edge_color='black', arrows=True)
plt.show()
# render pydot by calling dot, no file saved to disk
A=nx.to_pydot(G, strict=True)
png_str = A.create_png(prog='dot')
# treat the dot output string as an image file
sio = BytesIO()
sio.write(png_str)
sio.seek(0)
img = mpimg.imread(sio)
# plot the image
imgplot = plt.imshow(img, aspect='equal')
plt.show(block=False)
로컬로 실행할 수있는 전체 소스 또는 스 니펫을 공유 할 수 있습니다. –
관련 항목 : https://stackoverflow.com/a/1266082/1959808 –