From c3ced96e83342fa88f522da96a015e65c65d9133 Mon Sep 17 00:00:00 2001 From: Massimo Santini Date: Wed, 3 Nov 2021 12:17:15 +0100 Subject: [PATCH] Extracting positions from layout should use vertex number, not index. To convert the output of the layout algorithm to the dictionary mapping vertices to their positions one must use the vertex number, not the vertex index. This is particularly evident if the graph is a masked subgraph, in witch the i-th vertex needs not to be i. --- jgrapht/drawing/draw_matplotlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jgrapht/drawing/draw_matplotlib.py b/jgrapht/drawing/draw_matplotlib.py index 2d966b4..506380e 100644 --- a/jgrapht/drawing/draw_matplotlib.py +++ b/jgrapht/drawing/draw_matplotlib.py @@ -764,7 +764,7 @@ def layout(g, name=None, area=(0, 0, 10, 10), **kwargs): result = alg(g, area, **args) positions = {} for i, vertex in enumerate(g.vertices): - x, y = result.get_vertex_location(i) + x, y = result.get_vertex_location(vertex) positions[vertex] = (x, y) return positions