(file_name, sample_method, num_nodes, save_figure)
| 208 | @click.option('--num_nodes', default=3, help='Number of nodes in the subgraph') |
| 209 | @click.option('--save_figure', default=False, help='Save the figure') |
| 210 | def sample_subgraph(file_name, sample_method, num_nodes, save_figure): |
| 211 | # Create a graph sampler |
| 212 | random.seed(0) |
| 213 | sampler = GraphSampler(file_name=file_name) |
| 214 | |
| 215 | # Sample a sub-graph |
| 216 | sub_G = sampler.sample_subgraph(num_nodes, sample_method=sample_method) |
| 217 | print("Sub-graph nodes:", sub_G.nodes) |
| 218 | print("Sub-graph edges:", sub_G.edges) |
| 219 | |
| 220 | # Visualize the sub-graph |
| 221 | if save_figure: |
| 222 | pos = nx.circular_layout(sub_G) |
| 223 | nx.draw_networkx_nodes(sub_G, pos, node_color="skyblue", node_size=300) |
| 224 | nx.draw_networkx_edges(sub_G, pos, arrows=True) |
| 225 | nx.draw_networkx_labels(sub_G, pos, font_size=8) |
| 226 | plt.axis("off") |
| 227 | plt.tight_layout() |
| 228 | plt.savefig("test.png") |
| 229 | |
| 230 | |
| 231 |
no test coverage detected