| 6 | @click.command() |
| 7 | @click.option('--data_dir') |
| 8 | def visialize_graph(data_dir): |
| 9 | graph_file = f"{data_dir}/graph_desc.json" |
| 10 | with open(graph_file, "r") as f: |
| 11 | data = json.load(f) |
| 12 | |
| 13 | G = nx.DiGraph() |
| 14 | |
| 15 | for node in data["nodes"]: |
| 16 | G.add_node(node["id"]) |
| 17 | |
| 18 | for link in data["links"]: |
| 19 | G.add_edge(link["source"], link["target"]) |
| 20 | |
| 21 | pos = nx.spring_layout(G) |
| 22 | pos = nx.random_layout(G) |
| 23 | pos = nx.kamada_kawai_layout(G) |
| 24 | |
| 25 | # Show the visualization |
| 26 | plt.figure(figsize=(60, 60), dpi=80) |
| 27 | plt.tight_layout() |
| 28 | plt.axis("off") |
| 29 | plt.show() |
| 30 | |
| 31 | nx.draw_networkx_nodes(G, pos, node_color="skyblue", node_size=1200) |
| 32 | nx.draw_networkx_edges(G, pos, arrows=True, arrowsize=40) |
| 33 | nx.draw_networkx_labels(G, pos, font_size=50, font_color="green", font_weight="bold") |
| 34 | plt.savefig(graph_file.replace(".json", ".pdf")) |
| 35 | |
| 36 | if __name__ == "__main__": |
| 37 | visialize_graph() |