Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ sidebar_option = st.sidebar.radio("Select an option",
|
|
| 15 |
"Drawing: House With Colors", "Drawing: Labels And Colors",
|
| 16 |
"Drawing: Multipartite Layout", "Drawing: Node Colormap",
|
| 17 |
"Drawing: Rainbow Coloring", "Drawing: Random Geometric Graph","Drawing: Self-loops",
|
| 18 |
-
"Drawing: Simple Path"])
|
| 19 |
|
| 20 |
# Helper function to draw and display graph
|
| 21 |
def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
@@ -23,6 +23,68 @@ def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
| 23 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 24 |
st.pyplot(plt)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# Function to display Drawing: Simple Path
|
| 27 |
def display_simple_path():
|
| 28 |
st.title("Drawing: Simple Path")
|
|
|
|
| 15 |
"Drawing: House With Colors", "Drawing: Labels And Colors",
|
| 16 |
"Drawing: Multipartite Layout", "Drawing: Node Colormap",
|
| 17 |
"Drawing: Rainbow Coloring", "Drawing: Random Geometric Graph","Drawing: Self-loops",
|
| 18 |
+
"Drawing: Simple Path", "Drawing: Spectral Embedding"])
|
| 19 |
|
| 20 |
# Helper function to draw and display graph
|
| 21 |
def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
|
|
| 23 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 24 |
st.pyplot(plt)
|
| 25 |
|
| 26 |
+
# Function to display Drawing: Spectral Embedding
|
| 27 |
+
def display_spectral_embedding():
|
| 28 |
+
st.title("Drawing: Spectral Embedding")
|
| 29 |
+
|
| 30 |
+
option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
|
| 31 |
+
|
| 32 |
+
if option == "Default Example":
|
| 33 |
+
# Default example of spectral embedding with a grid graph
|
| 34 |
+
options = {"node_color": "C0", "node_size": 100}
|
| 35 |
+
G = nx.grid_2d_graph(6, 6)
|
| 36 |
+
|
| 37 |
+
fig, axs = plt.subplots(3, 3, figsize=(12, 12))
|
| 38 |
+
axs = axs.flatten()
|
| 39 |
+
for i in range(7):
|
| 40 |
+
if i == 0:
|
| 41 |
+
nx.draw_spectral(G, **options, ax=axs[i])
|
| 42 |
+
elif i == 1:
|
| 43 |
+
G.remove_edge((2, 2), (2, 3))
|
| 44 |
+
nx.draw_spectral(G, **options, ax=axs[i])
|
| 45 |
+
elif i == 2:
|
| 46 |
+
G.remove_edge((3, 2), (3, 3))
|
| 47 |
+
nx.draw_spectral(G, **options, ax=axs[i])
|
| 48 |
+
elif i == 3:
|
| 49 |
+
G.remove_edge((2, 2), (3, 2))
|
| 50 |
+
nx.draw_spectral(G, **options, ax=axs[i])
|
| 51 |
+
elif i == 4:
|
| 52 |
+
G.remove_edge((2, 3), (3, 3))
|
| 53 |
+
nx.draw_spectral(G, **options, ax=axs[i])
|
| 54 |
+
elif i == 5:
|
| 55 |
+
G.remove_edge((1, 2), (1, 3))
|
| 56 |
+
nx.draw_spectral(G, **options, ax=axs[i])
|
| 57 |
+
elif i == 6:
|
| 58 |
+
G.remove_edge((4, 2), (4, 3))
|
| 59 |
+
nx.draw_spectral(G, **options, ax=axs[i])
|
| 60 |
+
|
| 61 |
+
st.pyplot(fig)
|
| 62 |
+
|
| 63 |
+
elif option == "Create your own":
|
| 64 |
+
# User can interactively modify the grid and see the results
|
| 65 |
+
grid_size = st.slider("Choose grid size (n x n):", min_value=3, max_value=10, value=6)
|
| 66 |
+
G_custom = nx.grid_2d_graph(grid_size, grid_size)
|
| 67 |
+
|
| 68 |
+
# Edge removal logic
|
| 69 |
+
removed_edges = st.multiselect("Choose edges to remove (e.g., (0, 0) to (0, 1)):", list(G_custom.edges))
|
| 70 |
+
|
| 71 |
+
# Remove selected edges
|
| 72 |
+
G_custom.remove_edges_from(removed_edges)
|
| 73 |
+
|
| 74 |
+
options = {"node_color": "C0", "node_size": 100}
|
| 75 |
+
fig, axs = plt.subplots(3, 3, figsize=(12, 12))
|
| 76 |
+
axs = axs.flatten()
|
| 77 |
+
|
| 78 |
+
# Visualize the modified graph
|
| 79 |
+
for i in range(7):
|
| 80 |
+
nx.draw_spectral(G_custom, **options, ax=axs[i])
|
| 81 |
+
|
| 82 |
+
st.pyplot(fig)
|
| 83 |
+
|
| 84 |
+
# Display Drawing: Spectral Embedding if selected
|
| 85 |
+
if sidebar_option == "Drawing: Spectral Embedding":
|
| 86 |
+
display_spectral_embedding()
|
| 87 |
+
|
| 88 |
# Function to display Drawing: Simple Path
|
| 89 |
def display_simple_path():
|
| 90 |
st.title("Drawing: Simple Path")
|