Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,9 @@ sidebar_option = st.sidebar.radio("Select an option",
|
|
| 12 |
"Basic: Simple graph Directed", "Drawing: Custom Node Position",
|
| 13 |
"Drawing: Cluster Layout", "Drawing: Degree Analysis",
|
| 14 |
"Drawing: Ego Graph", "Drawing: Eigenvalues", "Drawing: Four Grids",
|
| 15 |
-
"Drawing: House With Colors", "Drawing: Labels And Colors",
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Helper function to draw and display graph
|
| 18 |
def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
@@ -20,6 +22,33 @@ def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
| 20 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 21 |
st.pyplot(plt)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# Function to create a multipartite graph
|
| 24 |
def multilayered_graph(*subset_sizes):
|
| 25 |
G = nx.Graph()
|
|
|
|
| 12 |
"Basic: Simple graph Directed", "Drawing: Custom Node Position",
|
| 13 |
"Drawing: Cluster Layout", "Drawing: Degree Analysis",
|
| 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 |
+
|
| 18 |
|
| 19 |
# Helper function to draw and display graph
|
| 20 |
def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
|
|
| 22 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 23 |
st.pyplot(plt)
|
| 24 |
|
| 25 |
+
# Function to display Drawing: Node Colormap
|
| 26 |
+
def display_node_colormap():
|
| 27 |
+
st.title("Drawing: Node Colormap")
|
| 28 |
+
|
| 29 |
+
option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
|
| 30 |
+
|
| 31 |
+
if option == "Default Example":
|
| 32 |
+
G = nx.cycle_graph(24)
|
| 33 |
+
pos = nx.circular_layout(G)
|
| 34 |
+
nx.draw(G, pos, node_color=range(24), node_size=800, cmap=plt.cm.Blues)
|
| 35 |
+
st.pyplot(plt)
|
| 36 |
+
|
| 37 |
+
elif option == "Create your own":
|
| 38 |
+
num_nodes = st.number_input("Number of nodes:", min_value=2, max_value=100, value=24)
|
| 39 |
+
color_map = st.selectbox("Select a colormap:", plt.colormaps(), index=plt.colormaps().index('Blues'))
|
| 40 |
+
|
| 41 |
+
if st.button("Generate Graph"):
|
| 42 |
+
# Create cycle graph with custom number of nodes
|
| 43 |
+
G_custom = nx.cycle_graph(num_nodes)
|
| 44 |
+
pos = nx.circular_layout(G_custom)
|
| 45 |
+
nx.draw(G_custom, pos, node_color=range(num_nodes), node_size=800, cmap=plt.get_cmap(color_map))
|
| 46 |
+
st.pyplot(plt)
|
| 47 |
+
|
| 48 |
+
# Display Drawing: Node Colormap if selected
|
| 49 |
+
if sidebar_option == "Drawing: Node Colormap":
|
| 50 |
+
display_node_colormap()
|
| 51 |
+
|
| 52 |
# Function to create a multipartite graph
|
| 53 |
def multilayered_graph(*subset_sizes):
|
| 54 |
G = nx.Graph()
|