Update app.py
Browse files
app.py
CHANGED
@@ -98,12 +98,23 @@ def visualizar_grafo():
|
|
98 |
if len(G.nodes) == 0:
|
99 |
print("鈿狅笍 Warning: The graph is empty! Check if data was loaded correctly.")
|
100 |
plt.text(0.5, 0.5, "No data available", fontsize=12, ha='center')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
-
pos = nx.spring_layout(G)
|
103 |
edge_labels = nx.get_edge_attributes(G, 'label')
|
104 |
-
nx.draw(G, pos, with_labels=True, node_color='lightblue', edge_color='gray', node_size=2000, font_size=10)
|
105 |
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=8)
|
106 |
-
|
|
|
107 |
plt.savefig("graph.png")
|
108 |
plt.close()
|
109 |
|
|
|
98 |
if len(G.nodes) == 0:
|
99 |
print("鈿狅笍 Warning: The graph is empty! Check if data was loaded correctly.")
|
100 |
plt.text(0.5, 0.5, "No data available", fontsize=12, ha='center')
|
101 |
+
plt.savefig("graph.png")
|
102 |
+
plt.close()
|
103 |
+
return "graph.png"
|
104 |
+
|
105 |
+
# 馃搶 1. Calcular betweenness centrality
|
106 |
+
centrality = nx.betweenness_centrality(G)
|
107 |
+
pos = nx.kamada_kawai_layout(G)
|
108 |
+
node_sizes = [2000 + 8000 * centrality[node] for node in G.nodes()] # Tama帽o base 2000, escalar con betweenness
|
109 |
+
nx.draw(
|
110 |
+
G, pos, with_labels=True, node_color='lightblue', edge_color='gray',
|
111 |
+
node_size=node_sizes, font_size=10
|
112 |
+
)
|
113 |
|
|
|
114 |
edge_labels = nx.get_edge_attributes(G, 'label')
|
|
|
115 |
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=8)
|
116 |
+
|
117 |
+
plt.title("Red de Aportes - Optimizada por Betweenness")
|
118 |
plt.savefig("graph.png")
|
119 |
plt.close()
|
120 |
|