Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -128,30 +128,29 @@ def display_custom_node_position():
|
|
128 |
# Function to display Cluster Layout for Drawing: Cluster Layout
|
129 |
def display_cluster_layout():
|
130 |
st.title("Drawing: Cluster Layout")
|
131 |
-
|
132 |
-
option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
communities = nx.community.greedy_modularity_communities(G)
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
|
148 |
# Nodes colored by cluster
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
|
153 |
-
|
154 |
-
|
|
|
|
|
155 |
|
156 |
# Display Basic: Properties if selected
|
157 |
if sidebar_option == "Basic: Properties":
|
|
|
128 |
# Function to display Cluster Layout for Drawing: Cluster Layout
|
129 |
def display_cluster_layout():
|
130 |
st.title("Drawing: Cluster Layout")
|
|
|
|
|
131 |
|
132 |
+
G = nx.davis_southern_women_graph() # Example graph
|
133 |
+
communities = nx.community.greedy_modularity_communities(G)
|
|
|
134 |
|
135 |
+
# Compute positions for the node clusters as if they were themselves nodes in a supergraph using a larger scale factor
|
136 |
+
supergraph = nx.cycle_graph(len(communities))
|
137 |
+
superpos = nx.spring_layout(G, scale=50, seed=429)
|
138 |
|
139 |
+
# Use the "supernode" positions as the center of each node cluster
|
140 |
+
centers = list(superpos.values())
|
141 |
+
pos = {}
|
142 |
+
for center, comm in zip(centers, communities):
|
143 |
+
pos.update(nx.spring_layout(nx.subgraph(G, comm), center=center, seed=1430))
|
144 |
|
145 |
# Nodes colored by cluster
|
146 |
+
for nodes, clr in zip(communities, ("tab:blue", "tab:orange", "tab:green")):
|
147 |
+
nx.draw_networkx_nodes(G, pos=pos, nodelist=nodes, node_color=clr, node_size=100)
|
148 |
+
nx.draw_networkx_edges(G, pos=pos)
|
149 |
|
150 |
+
plt.tight_layout()
|
151 |
+
st.pyplot(plt)
|
152 |
+
|
153 |
+
|
154 |
|
155 |
# Display Basic: Properties if selected
|
156 |
if sidebar_option == "Basic: Properties":
|