framework/freecad_workbench/freecad/robossembler/graph_visualisation.py

26 lines
761 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()