Update app.py
Browse files
app.py
CHANGED
|
@@ -10,8 +10,8 @@ sidebar_option = st.sidebar.radio("Select an option",
|
|
| 10 |
"Basic: Read and write graphs", "Basic: Simple graph",
|
| 11 |
"Basic: Simple graph Directed", "Drawing: Custom Node Position",
|
| 12 |
"Drawing: Cluster Layout", "Drawing: Degree Analysis",
|
| 13 |
-
"Drawing: Ego Graph", "Drawing: Eigenvalues", "Drawing: Four Grids"
|
| 14 |
-
|
| 15 |
|
| 16 |
# Helper function to draw and display graph
|
| 17 |
def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
@@ -19,6 +19,63 @@ def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
| 19 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 20 |
st.pyplot(plt)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# Function to display Four Grids visualization for Drawing: Four Grids
|
| 23 |
def display_four_grids():
|
| 24 |
st.title("Drawing: Four Grids")
|
|
|
|
| 10 |
"Basic: Read and write graphs", "Basic: Simple graph",
|
| 11 |
"Basic: Simple graph Directed", "Drawing: Custom Node Position",
|
| 12 |
"Drawing: Cluster Layout", "Drawing: Degree Analysis",
|
| 13 |
+
"Drawing: Ego Graph", "Drawing: Eigenvalues", "Drawing: Four Grids",
|
| 14 |
+
"Drawing: House With Colors"])
|
| 15 |
|
| 16 |
# Helper function to draw and display graph
|
| 17 |
def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
|
|
| 19 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 20 |
st.pyplot(plt)
|
| 21 |
|
| 22 |
+
# Function to display Drawing: House With Colors
|
| 23 |
+
def display_house_with_colors():
|
| 24 |
+
st.title("Drawing: House With Colors")
|
| 25 |
+
|
| 26 |
+
option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
|
| 27 |
+
|
| 28 |
+
if option == "Default Example":
|
| 29 |
+
# Create the house graph and explicitly set positions
|
| 30 |
+
G = nx.house_graph()
|
| 31 |
+
pos = {0: (0, 0), 1: (1, 0), 2: (0, 1), 3: (1, 1), 4: (0.5, 2.0)}
|
| 32 |
+
|
| 33 |
+
# Plot nodes with different properties for the "wall" and "roof" nodes
|
| 34 |
+
nx.draw_networkx_nodes(G, pos, node_size=3000, nodelist=[0, 1, 2, 3], node_color="tab:blue")
|
| 35 |
+
nx.draw_networkx_nodes(G, pos, node_size=2000, nodelist=[4], node_color="tab:orange")
|
| 36 |
+
nx.draw_networkx_edges(G, pos, alpha=0.5, width=6)
|
| 37 |
+
|
| 38 |
+
# Customize axes
|
| 39 |
+
ax = plt.gca()
|
| 40 |
+
ax.margins(0.11)
|
| 41 |
+
plt.tight_layout()
|
| 42 |
+
plt.axis("off")
|
| 43 |
+
st.pyplot(plt)
|
| 44 |
+
|
| 45 |
+
elif option == "Create your own":
|
| 46 |
+
# Allow the user to specify node positions and colors
|
| 47 |
+
st.write("Specify positions for the house graph nodes.")
|
| 48 |
+
|
| 49 |
+
positions = {}
|
| 50 |
+
for i in range(5):
|
| 51 |
+
x = st.number_input(f"X-coordinate for node {i}:", min_value=-10, max_value=10, value=0)
|
| 52 |
+
y = st.number_input(f"Y-coordinate for node {i}:", min_value=-10, max_value=10, value=0)
|
| 53 |
+
positions[i] = (x, y)
|
| 54 |
+
|
| 55 |
+
# Allow the user to specify colors for wall and roof nodes
|
| 56 |
+
wall_color = st.color_picker("Wall color:", "#0000FF")
|
| 57 |
+
roof_color = st.color_picker("Roof color:", "#FFA500")
|
| 58 |
+
|
| 59 |
+
if st.button("Generate"):
|
| 60 |
+
# Create the house graph with the specified positions
|
| 61 |
+
G_custom = nx.house_graph()
|
| 62 |
+
|
| 63 |
+
# Plot nodes with user-defined properties for wall and roof nodes
|
| 64 |
+
nx.draw_networkx_nodes(G_custom, positions, node_size=3000, nodelist=[0, 1, 2, 3], node_color=wall_color)
|
| 65 |
+
nx.draw_networkx_nodes(G_custom, positions, node_size=2000, nodelist=[4], node_color=roof_color)
|
| 66 |
+
nx.draw_networkx_edges(G_custom, positions, alpha=0.5, width=6)
|
| 67 |
+
|
| 68 |
+
# Customize axes
|
| 69 |
+
ax = plt.gca()
|
| 70 |
+
ax.margins(0.11)
|
| 71 |
+
plt.tight_layout()
|
| 72 |
+
plt.axis("off")
|
| 73 |
+
st.pyplot(plt)
|
| 74 |
+
|
| 75 |
+
# Display Drawing: House With Colors if selected
|
| 76 |
+
if sidebar_option == "Drawing: House With Colors":
|
| 77 |
+
display_house_with_colors()
|
| 78 |
+
|
| 79 |
# Function to display Four Grids visualization for Drawing: Four Grids
|
| 80 |
def display_four_grids():
|
| 81 |
st.title("Drawing: Four Grids")
|