Update app.py
Browse files
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 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
options=[str(edge) for edge in all_edges])
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
G_custom_copy.remove_edges_from(edges_to_remove)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
| 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":
|