Flux9665 commited on
Commit
de8b228
β€’
1 Parent(s): 3e5723e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -104,15 +104,15 @@ class Visualizer:
104
  if d <= thresh and (neighbor == entity2 or neighbor == entity1) and len(neighbors) < num_neighbors + 1:
105
  neighbors.add(entity1)
106
  neighbors.add(entity2)
107
- spring_tension = (thresh - d) * 10 # for vis purposes
108
  G.add_edge(entity1, entity2, weight=spring_tension)
109
  neighbors.remove(neighbor)
110
  for entity1, entity2, d in tqdm(normalized_distances):
111
  if entity2 in neighbors and entity1 in neighbors:
112
- spring_tension = thresh - d
113
  G.add_edge(entity1, entity2, weight=spring_tension)
114
 
115
- pos = nx.spring_layout(G, weight="weight") # Positions for all nodes
116
  edges = G.edges(data=True)
117
  nx.draw_networkx_nodes(G, pos, node_size=1, alpha=0.01)
118
  edges_connected_to_specific_node = [(u, v) for u, v in G.edges() if u == neighbor or v == neighbor]
@@ -121,7 +121,7 @@ class Visualizer:
121
  # nx.draw_networkx_edges(G, pos, edgelist=edges_not_connected_to_specific_node, edge_color='gray', alpha=0.1, width=1)
122
  for u, v, d in edges:
123
  if u == neighbor or v == neighbor:
124
- nx.draw_networkx_edge_labels(G, pos, edge_labels={(u, v): round((thresh - (d['weight'] / 10)), 2)}, font_color="red", alpha=0.4) # reverse modifications
125
  nx.draw_networkx_labels(G, pos, font_size=14, font_family='sans-serif', font_color='green')
126
  nx.draw_networkx_labels(G, pos, labels={neighbor: neighbor}, font_size=14, font_family='sans-serif', font_color='red')
127
  plt.title(f'Graph of {distance_type}')
 
104
  if d <= thresh and (neighbor == entity2 or neighbor == entity1) and len(neighbors) < num_neighbors + 1:
105
  neighbors.add(entity1)
106
  neighbors.add(entity2)
107
+ spring_tension = (thresh - d) * 1000 # for vis purposes
108
  G.add_edge(entity1, entity2, weight=spring_tension)
109
  neighbors.remove(neighbor)
110
  for entity1, entity2, d in tqdm(normalized_distances):
111
  if entity2 in neighbors and entity1 in neighbors:
112
+ spring_tension = (thresh - d) * 10
113
  G.add_edge(entity1, entity2, weight=spring_tension)
114
 
115
+ pos = nx.spring_layout(G, weight="weight", iterations=200, threshold=1e-6) # Positions for all nodes
116
  edges = G.edges(data=True)
117
  nx.draw_networkx_nodes(G, pos, node_size=1, alpha=0.01)
118
  edges_connected_to_specific_node = [(u, v) for u, v in G.edges() if u == neighbor or v == neighbor]
 
121
  # nx.draw_networkx_edges(G, pos, edgelist=edges_not_connected_to_specific_node, edge_color='gray', alpha=0.1, width=1)
122
  for u, v, d in edges:
123
  if u == neighbor or v == neighbor:
124
+ nx.draw_networkx_edge_labels(G, pos, edge_labels={(u, v): round((thresh - (d['weight'] / 1000)) * 100, 2)}, font_color="red", alpha=0.4) # reverse modifications
125
  nx.draw_networkx_labels(G, pos, font_size=14, font_family='sans-serif', font_color='green')
126
  nx.draw_networkx_labels(G, pos, labels={neighbor: neighbor}, font_size=14, font_family='sans-serif', font_color='red')
127
  plt.title(f'Graph of {distance_type}')