Skip to content

Commit

Permalink
fix: plot SC with max_order (#248)
Browse files Browse the repository at this point in the history
* fix: plot SC with max_order

* safety first

* safety first
  • Loading branch information
maximelucas authored Dec 9, 2022
1 parent 9f32d2c commit 86b8ccc
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions xgi/drawing/xgi_pylab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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,
Expand All @@ -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.)
Expand Down

0 comments on commit 86b8ccc

Please sign in to comment.