From 86b8cccabfb3eb1544b316b19809902200833ed9 Mon Sep 17 00:00:00 2001 From: Maxime Lucas Date: Fri, 9 Dec 2022 16:16:22 +0100 Subject: [PATCH] fix: plot SC with max_order (#248) * fix: plot SC with max_order * safety first * safety first --- xgi/drawing/xgi_pylab.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/xgi/drawing/xgi_pylab.py b/xgi/drawing/xgi_pylab.py index d8046f0c2..b147cc282 100644 --- a/xgi/drawing/xgi_pylab.py +++ b/xgi/drawing/xgi_pylab.py @@ -362,6 +362,10 @@ def draw_xgi_hyperedges( draw_node_labels draw_hyperedge_labels """ + + if not max_order: + max_order = max_edge_order(H) + dyad_color = _color_arg_to_dict(dyad_color, H.edges, settings["dyad_color_cmap"]) dyad_lw = _scalar_arg_to_dict( dyad_lw, H.edges, settings["min_dyad_lw"], settings["max_dyad_lw"] @@ -478,9 +482,17 @@ def draw_xgi_simplices( draw_node_labels draw_hyperedge_labels """ + + if max_order: + max_edges = SC.edges.filterby("order", max_order, "leq").members() + SC = SimplicialComplex(max_edges) # SC without simplices larger than max_order + # Plot only the maximal simplices, thus let's convert the SC to H H_ = convert.from_simplicial_complex_to_hypergraph(SC) + if not max_order: + max_order = max_edge_order(H_) + dyad_color = _color_arg_to_dict(dyad_color, H_.edges, settings["dyad_color_cmap"]) dyad_lw = _scalar_arg_to_dict( dyad_lw, @@ -494,15 +506,20 @@ def draw_xgi_simplices( # Looping over the hyperedges of different order (reversed) -- nodes will be plotted separately for id, he in H_.edges.members(dtype=dict).items(): d = len(he) - 1 - if d > max_order: - continue + if d == 1: # Drawing the edges he = list(he) x_coords = [pos[he[0]][0], pos[he[1]][0]] y_coords = [pos[he[0]][1], pos[he[1]][1]] - line = plt.Line2D(x_coords, y_coords, color=dyad_color[id], lw=dyad_lw[id]) + line = plt.Line2D( + x_coords, + y_coords, + color=dyad_color[id], + lw=dyad_lw[id], + zorder=max_order - 1, + ) ax.add_line(line) else: # Hyperedges of order d (d=2: triangles, etc.)