From e975e91a0cdf6f1f4f6bd4fa1f63576f27d408a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Alexandre=20C=C3=B4t=C3=A9?= Date: Wed, 24 Jul 2024 15:32:09 -0400 Subject: [PATCH] Use integers instead of node names before using pydot_layout. --- textworld/render/graph.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/textworld/render/graph.py b/textworld/render/graph.py index 75e09ad7..88db1c70 100644 --- a/textworld/render/graph.py +++ b/textworld/render/graph.py @@ -88,7 +88,10 @@ def show_graph(facts: Iterable[Proposition], G = build_graph_from_facts(facts) plt.figure(figsize=(16, 9)) - pos = nx.drawing.nx_pydot.pydot_layout(G, prog="fdp") + # To avoid name issue with nx_pydot, we convert node labels to integers. + H = nx.convert_node_labels_to_integers(G, label_attribute='node_label') + H_layout = nx.drawing.nx_pydot.pydot_layout(H, prog="fdp") + pos = {H.nodes[n]['node_label']: p for n, p in H_layout.items()} edge_labels_pos = {} trace3_list = []