shukdevdatta123 commited on
Commit
79f8574
·
verified ·
1 Parent(s): 1f8cc08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -66,27 +66,31 @@ def display_spectral_embedding():
66
  G_custom = nx.grid_2d_graph(grid_size, grid_size)
67
 
68
  # List all edges to allow removal
69
- all_edges = list(G_custom.edges)
70
 
71
- fig, axs = plt.subplots(3, 3, figsize=(12, 12))
72
- axs = axs.flatten()
73
 
74
- # Loop through each subplot and allow edge removal individually
75
- for i in range(7):
76
- selected_edges = st.multiselect(f"Select edges to remove for graph {i+1}:",
77
- options=[str(edge) for edge in all_edges])
78
 
79
- # Convert the selected edges from string to tuple
80
- edges_to_remove = [tuple(eval(edge)) for edge in selected_edges]
 
 
81
 
82
- # Remove the selected edges
83
- G_custom_copy = G_custom.copy()
84
- G_custom_copy.remove_edges_from(edges_to_remove)
85
 
86
- # Draw the graph with removed edges
87
- nx.draw_spectral(G_custom_copy, **{"node_color": "C0", "node_size": 100}, ax=axs[i])
 
88
 
89
- st.pyplot(fig)
 
 
 
90
 
91
  # Display Drawing: Spectral Embedding if selected
92
  if sidebar_option == "Drawing: Spectral Embedding":
 
66
  G_custom = nx.grid_2d_graph(grid_size, grid_size)
67
 
68
  # List all edges to allow removal
69
+ all_edges = list(G_custom.edges())
70
 
71
+ # Add "Generate" button
72
+ generate_button = st.button("Generate Graph")
73
 
74
+ if generate_button:
75
+ fig, axs = plt.subplots(3, 3, figsize=(12, 12))
76
+ axs = axs.flatten()
 
77
 
78
+ # Loop through each subplot and allow edge removal individually
79
+ for i in range(7):
80
+ selected_edges = st.multiselect(f"Select edges to remove for graph {i+1}:",
81
+ options=[str(edge) for edge in all_edges])
82
 
83
+ # Convert the selected edges from string to tuple
84
+ edges_to_remove = [tuple(eval(edge)) for edge in selected_edges]
 
85
 
86
+ # Remove the selected edges
87
+ G_custom_copy = G_custom.copy()
88
+ G_custom_copy.remove_edges_from(edges_to_remove)
89
 
90
+ # Draw the graph with removed edges
91
+ nx.draw_spectral(G_custom_copy, **{"node_color": "C0", "node_size": 100}, ax=axs[i])
92
+
93
+ st.pyplot(fig)
94
 
95
  # Display Drawing: Spectral Embedding if selected
96
  if sidebar_option == "Drawing: Spectral Embedding":