그래프의 이미지를 분리하는 방법은 무엇입니까? (How to separate images of graphs?)


문제 설명

그래프의 이미지를 분리하는 방법은 무엇입니까? (How to separate images of graphs?)

별도의 그래프의 가장자리가 교차하지 않는 완전한 그래프를 그려야 합니다. matplotlib에서 좌표를 사용하려고 시도했지만 작동하지 않았습니다. 이것이 코드입니다:

import networkx as nx
import matplotlib.pyplot as plt


G=nx.Graph()
G.add_edge("1", "2")
G.add_edge("2","3")
G.add_edge("3","4")
G.add_edge("1","3")
G.add_edge("1","4")
G.add_edge("2","4")

pos = {1: (0, 0), 2: (1, 1), 3: (0, 1) , 4: (1, 0)}

F=nx.Graph()
F.add_edge("5", "6")
F.add_edge("6","7")
F.add_edge("7","8")
F.add_edge("5","7")
F.add_edge("5","8")
F.add_edge("6","8")

pos = {5: (10, 10), 6: (11, 11), 7: (10, 11) , 8: (11, 10)}

E=nx.Graph()
E.add_edge("9", "10")
E.add_edge("10","11")
E.add_edge("9","11")

pos = nx.random_layout(E)

Y=nx.Graph()
Y.add_node("12")

pos = nx.random_layout(Y)

nx.draw(G, with_labels = True, node_color = 'white')
nx.draw(F, with_labels = True, node_color = 'white')
nx.draw(E, with_labels = True, node_color = 'white')
nx.draw(Y, with_labels = True, node_color = 'white')

plt.savefig('labels.png')
plt.show()

결과

여기에 이미지 설명 입력


참조 솔루션

방법 1:

You create the pos variable and overwrite it multiple times without using it at any point. Simply create multiple with non overlapping drawing areas:

import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph()
G.add_edge("1", "2")
G.add_edge("2", "3")
G.add_edge("3", "4")
G.add_edge("1", "3")
G.add_edge("1", "4")
G.add_edge("2", "4")

pos_G = {"1": (0, 0), "2": (1, 1), "3": (0, 1), "4": (1, 0)}

F = nx.Graph()
F.add_edge("5", "6")
F.add_edge("6", "7")
F.add_edge("7", "8")
F.add_edge("5", "7")
F.add_edge("5", "8")
F.add_edge("6", "8")

pos_F = {"5": (10, 10), "6": (11, 11), "7": (10, 11), "8": (11, 10)}

E = nx.Graph()
E.add_edge("9", "10")
E.add_edge("10", "11")
E.add_edge("9", "11")

pos_E = nx.random_layout(E)
pos_E = {node: pos + 3 for node, pos in pos_E.items()}

Y = nx.Graph()
Y.add_node("12")

pos_Y = nx.random_layout(Y)
pos_Y = {node: pos + 5 for node, pos in pos_Y.items()}

nx.draw(G, pos_G, with_labels=True, node_color='white')
nx.draw(F, pos_F, with_labels=True, node_color='white')
nx.draw(E, pos_E, with_labels=True, node_color='white')
nx.draw(Y, pos_Y, with_labels=True, node_color='white')

plt.savefig('labels.png')

plt.show()
</code></pre>

Result

enter image description here

(by DSSSparky05)

참조 문서

  1. How to separate images of graphs? (CC BY‑SA 2.5/3.0/4.0)

#networkx #python-3.x #graph-theory






관련 질문

단순 팻테일 로그 비닝 (Simple fat-tailed log-binning)

NetworkX - 노드 묶기 중지 - 시도된 Scale/K 매개변수 (NetworkX - Stop Nodes from Bunching Up - Tried Scale/K parameters)

문자열의 int 부분으로 문자열 레이블의 노드에 액세스 (Access a node of string label with an int part of the string)

시계열 분석을 위해 Pandas Groupby 및 date_range를 사용하는 동안 오류가 발생했습니다. (Error using Pandas Groupby and date_range for timeseries analysis)

regraph 계층 구조에서 가장자리 속성을 자리 표시자로 사용하는 방법이 있습니까? (Is there a way to have edge attributes as placeholders in a regraph hierarchy?)

networkx .module 'matplotlib.pyplot'에서 그래프를 그리는 동안 오류가 발생했습니다. (Error while drawing a graph in networkx .module 'matplotlib.pyplot' has no attribute 'ishold')

svg의 NetworkX node_shape (NetworkX node_shape from svg)

그래프를 통해 그래프 노드인 클래스 인스턴스의 속성에 액세스하는 방법은 무엇입니까? (How to access attributes of a class instance which is a graph node via the graph?)

그래프의 이미지를 분리하는 방법은 무엇입니까? (How to separate images of graphs?)

networkx 도면을 업데이트하는 방법 (How to update a networkx drawing)

그래프 노드 간의 메시지 흐름을 위한 Python 함수 (Python function for message flow between nodes of a graph)

networkx에서 임의의 에지 가중치를 사용하여 여러 임의의 그래프를 효율적으로 생성하는 방법 (How to efficiently generate multiple random graphs with random edge weights in networkx)







코멘트