From ca4e5263e5296778e9f24617a5fcfd333d3756e9 Mon Sep 17 00:00:00 2001 From: iaciac Date: Wed, 6 Jul 2022 17:11:43 +0200 Subject: [PATCH] fixing bug for non-int node labels when plotting --- xgi/drawing/layout.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/xgi/drawing/layout.py b/xgi/drawing/layout.py index 5f9b1fd56..600214a41 100644 --- a/xgi/drawing/layout.py +++ b/xgi/drawing/layout.py @@ -147,7 +147,13 @@ def barycenter_spring_layout(H, return_phantom_graph=False): G.add_edge(i, j) # Adding phantom nodes and connections therein - phantom_node_id = max(H.nodes) + 1 + # I will start from the first int node-label available + try: + phantom_node_id = max([n for n in H.nodes if isinstance(n, int)]) + 1 + except ValueError: + # The list of node-labels has no integers, so I start from 0 + phantom_node_id = 0 + # Looping over the hyperedges of different order (from triples up) for d in range(2, max_edge_order(H) + 1): # Hyperedges of order d (d=2: triplets, etc.) @@ -219,7 +225,13 @@ def weighted_barycenter_spring_layout(H, return_phantom_graph=False): G.add_edge(i, j, weight=d) # Adding phantom nodes and connections therein - phantom_node_id = max(H.nodes) + 1 + # I will start from the first int node-label available + try: + phantom_node_id = max([n for n in H.nodes if isinstance(n, int)]) + 1 + except ValueError: + # The list of node-labels has no integers, so I start from 0 + phantom_node_id = 0 + # Looping over the hyperedges of different order (from triples up) for d in range(2, max_edge_order(H) + 1): # Hyperedges of order d (d=2: triplets, etc.)