26 lines
761 B
Python
26 lines
761 B
Python
import json
|
||
import networkx as nx
|
||
import matplotlib.pyplot as plt
|
||
|
||
# Загружаем данные из файла
|
||
with open('adjacency_matrix.json', 'r') as file:
|
||
data = json.load(file)
|
||
|
||
# Создаем пустой граф
|
||
G = nx.Graph()
|
||
|
||
# Добавляем узлы
|
||
for part in data['allParts']:
|
||
G.add_node(part)
|
||
|
||
# Добавляем ребра
|
||
for part, connections in data['matrix'].items():
|
||
for connected_part in connections:
|
||
G.add_edge(part, connected_part)
|
||
|
||
# Визуализируем граф
|
||
plt.figure(figsize=(10, 8))
|
||
pos = nx.spring_layout(G)
|
||
nx.draw(G, pos, with_labels=True, node_size=100, node_color='lightblue', font_size=10, font_weight='bold', edge_color='gray')
|
||
plt.title('Graph of Part Connections')
|
||
plt.show()
|