shukdevdatta123 commited on
Commit
0586bdc
·
verified ·
1 Parent(s): 60586bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -14,9 +14,8 @@ sidebar_option = st.sidebar.radio("Select an option",
14
  "Drawing: Ego Graph", "Drawing: Eigenvalues", "Drawing: Four Grids",
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
-
19
-
20
 
21
  # Helper function to draw and display graph
22
  def draw_graph(G, pos=None, title="Graph Visualization"):
@@ -24,6 +23,38 @@ def draw_graph(G, pos=None, title="Graph Visualization"):
24
  nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
25
  st.pyplot(plt)
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  # Function to display Drawing: Self-loops
28
  def display_self_loops():
29
  st.title("Drawing: Self-loops")
 
14
  "Drawing: Ego Graph", "Drawing: Eigenvalues", "Drawing: Four Grids",
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
  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")
29
+
30
+ option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
31
+
32
+ if option == "Default Example":
33
+ # Default example of a simple path graph
34
+ G = nx.path_graph(8)
35
+ pos = nx.spring_layout(G, seed=47) # Seed layout for reproducibility
36
+
37
+ # Draw the graph
38
+ nx.draw(G, pos=pos)
39
+ st.pyplot(plt)
40
+
41
+ elif option == "Create your own":
42
+ # User can create their own path graph with a custom number of nodes
43
+ num_nodes = st.number_input("Number of nodes in the path:", min_value=2, max_value=50, value=8)
44
+
45
+ if st.button("Generate Graph"):
46
+ # Generate a path graph with user-specified number of nodes
47
+ G_custom = nx.path_graph(num_nodes)
48
+ pos = nx.spring_layout(G_custom, seed=47) # Seed layout for reproducibility
49
+
50
+ # Draw the graph
51
+ nx.draw(G_custom, pos=pos)
52
+ st.pyplot(plt)
53
+
54
+ # Display Drawing: Simple Path if selected
55
+ if sidebar_option == "Drawing: Simple Path":
56
+ display_simple_path()
57
+
58
  # Function to display Drawing: Self-loops
59
  def display_self_loops():
60
  st.title("Drawing: Self-loops")