shukdevdatta123 commited on
Commit
337b460
·
verified ·
1 Parent(s): 22ca56a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -28
app.py CHANGED
@@ -119,7 +119,7 @@ def default_example():
119
  ax.grid(False)
120
  # Suppress tick labels
121
  for dim in (ax.xaxis, ax.yaxis, ax.zaxis):
122
- dim.set_ticks([])
123
  # Set axes labels
124
  ax.set_xlabel("x")
125
  ax.set_ylabel("y")
@@ -135,37 +135,41 @@ def create_own_graph():
135
  nodes = st.number_input("Number of nodes", min_value=2, max_value=50, value=20)
136
  seed = st.number_input("Seed for layout", value=779)
137
 
138
- # Generate graph and layout
139
- G = nx.cycle_graph(nodes)
140
- pos = nx.spring_layout(G, dim=3, seed=seed)
141
-
142
- # Extract node and edge positions
143
- node_xyz = np.array([pos[v] for v in sorted(G)])
144
- edge_xyz = np.array([(pos[u], pos[v]) for u, v in G.edges()])
145
 
146
- # Create the 3D figure
147
- fig = plt.figure()
148
- ax = fig.add_subplot(111, projection="3d")
 
 
 
 
 
149
 
150
- # Plot the nodes
151
- ax.scatter(*node_xyz.T, s=100, ec="w")
 
152
 
153
- # Plot the edges
154
- for vizedge in edge_xyz:
155
- ax.plot(*vizedge.T, color="tab:gray")
156
 
157
- def _format_axes(ax):
158
- """Visualization options for the 3D axes."""
159
- ax.grid(False)
160
- for dim in (ax.xaxis, ax.yaxis, ax.zaxis):
161
- dim.set_ticks([])
162
- ax.set_xlabel("x")
163
- ax.set_ylabel("y")
164
- ax.set_zlabel("z")
165
 
166
- _format_axes(ax)
167
- fig.tight_layout()
168
- st.pyplot(fig)
 
 
 
 
 
 
 
 
 
169
 
170
  if sidebar_option == "3D Drawing: Basic Matplotlib":
171
  st.title("3D Drawing: Basic Matplotlib")
@@ -174,7 +178,7 @@ if sidebar_option == "3D Drawing: Basic Matplotlib":
174
  graph_mode = st.radio(
175
  "Choose a Mode:",
176
  ("Default Example", "Create Your Own"),
177
- help="Default example shows a dodecahedral graph, or you can create your own custom graph."
178
  )
179
 
180
  # Display the chosen option
 
119
  ax.grid(False)
120
  # Suppress tick labels
121
  for dim in (ax.xaxis, ax.yaxis, ax.zaxis):
122
+ dim.set_ticks([])
123
  # Set axes labels
124
  ax.set_xlabel("x")
125
  ax.set_ylabel("y")
 
135
  nodes = st.number_input("Number of nodes", min_value=2, max_value=50, value=20)
136
  seed = st.number_input("Seed for layout", value=779)
137
 
138
+ # Add a button to generate the graph
139
+ generate_button = st.button("Generate Graph")
 
 
 
 
 
140
 
141
+ if generate_button:
142
+ # Generate graph and layout
143
+ G = nx.cycle_graph(nodes)
144
+ pos = nx.spring_layout(G, dim=3, seed=seed)
145
+
146
+ # Extract node and edge positions
147
+ node_xyz = np.array([pos[v] for v in sorted(G)])
148
+ edge_xyz = np.array([(pos[u], pos[v]) for u, v in G.edges()])
149
 
150
+ # Create the 3D figure
151
+ fig = plt.figure()
152
+ ax = fig.add_subplot(111, projection="3d")
153
 
154
+ # Plot the nodes
155
+ ax.scatter(*node_xyz.T, s=100, ec="w")
 
156
 
157
+ # Plot the edges
158
+ for vizedge in edge_xyz:
159
+ ax.plot(*vizedge.T, color="tab:gray")
 
 
 
 
 
160
 
161
+ def _format_axes(ax):
162
+ """Visualization options for the 3D axes."""
163
+ ax.grid(False)
164
+ for dim in (ax.xaxis, ax.yaxis, ax.zaxis):
165
+ dim.set_ticks([])
166
+ ax.set_xlabel("x")
167
+ ax.set_ylabel("y")
168
+ ax.set_zlabel("z")
169
+
170
+ _format_axes(ax)
171
+ fig.tight_layout()
172
+ st.pyplot(fig)
173
 
174
  if sidebar_option == "3D Drawing: Basic Matplotlib":
175
  st.title("3D Drawing: Basic Matplotlib")
 
178
  graph_mode = st.radio(
179
  "Choose a Mode:",
180
  ("Default Example", "Create Your Own"),
181
+ help="Default example shows a cycle graph, or you can create your own custom graph."
182
  )
183
 
184
  # Display the chosen option