Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrote the multilayer function #486

Merged
merged 17 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 39 additions & 40 deletions docs/source/api/recipes/recipes.ipynb

Large diffs are not rendered by default.

641 changes: 641 additions & 0 deletions docs/source/api/tutorials/In Depth 4 - Drawing multilayer-style.ipynb

Large diffs are not rendered by default.

184 changes: 110 additions & 74 deletions docs/source/api/tutorials/Tutorial 5 - Plotting.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/source/api/tutorials/in_depth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ In Depth tutorials
In Depth 1 - Drawing nodes
In Depth 2 - Drawing hyperedges
In Depth 3 - Drawing DiHypergraphs
In Depth 4 - Drawing multilayer-style
116 changes: 88 additions & 28 deletions tests/drawing/test_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,84 +377,144 @@ def test_draw_hypergraph_hull(edgelist8):
plt.close()


def test_correct_number_of_collections_draw_multilayer(edgelist8):
def test_draw_multilayer(edgelist8):
# hypergraph
H = xgi.Hypergraph(edgelist8)

ax1 = xgi.draw_multilayer(H)
ax1, (node_coll, edge_coll) = xgi.draw_multilayer(H)
sizes = xgi.unique_edge_sizes(H)
num_planes = max(sizes) - min(sizes) + 1
num_layers = max(sizes) - min(sizes) + 1
num_node_collections = max(sizes) - min(sizes) + 1
num_edge_collections = H.num_edges
num_thru_lines_collections = 1
num_edge_collections = 1
num_dyad_collections = 1
num_interlayer_collections = 1

assert (
num_planes
+ num_node_collections
num_layers
+ num_dyad_collections
+ num_edge_collections
+ num_thru_lines_collections
+ num_interlayer_collections
+ num_node_collections
== len(ax1.collections)
)

# number of elements
assert len(ax1.lines) == 0
assert len(ax1.patches) == 0
offsets = node_coll.get_offsets()
assert offsets.shape[0] == H.num_nodes # nodes
assert len(ax1.collections) == 11

# zorder
assert node_coll.get_zorder() == 5 # nodes
assert edge_coll.get_zorder() == 2 # edges

# node_fc
assert np.all(
node_coll.get_facecolor() == np.array([[1, 1, 1, 1]])
) # white

# node_ec
assert np.all(
node_coll.get_edgecolor() == np.array([[0, 0, 0, 1]])
) # black

# node_lw
assert np.all(node_coll.get_linewidth() == np.array([1]))

# node_size
assert np.all(node_coll.get_sizes() == np.array([5**2]))

plt.close()

# max_order parameter
max_order = 2
ax2 = xgi.draw_multilayer(H, max_order=max_order)
ax2, (node_coll2, edge_coll2) = xgi.draw_multilayer(H, max_order=max_order)
sizes = [2, 3]
num_planes = max(sizes) - min(sizes) + 1
num_layers = max(sizes) - min(sizes) + 1
num_node_collections = max(sizes) - min(sizes) + 1
num_edge_collections = len(H.edges.filterby("size", [2, 3], "between"))
num_thru_lines_collections = 1
num_edge_collections = 1
num_dyad_collections = 1
num_interlayer_collections = 1

assert (
num_planes
num_layers
+ num_node_collections
+ num_edge_collections
+ num_thru_lines_collections
+ num_interlayer_collections
+ num_dyad_collections
== len(ax2.collections)
)

offsets = node_coll2.get_offsets()
assert offsets.shape[0] == H.num_nodes # nodes
plt.close()

# conn_lines parameter
ax3 = xgi.draw_multilayer(H, conn_lines=False)
ax3, (node_coll3, edge_coll3) = xgi.draw_multilayer(H, conn_lines=False)
sizes = xgi.unique_edge_sizes(H)
num_planes = max(sizes) - min(sizes) + 1
num_layers = max(sizes) - min(sizes) + 1
num_node_collections = max(sizes) - min(sizes) + 1
num_edge_collections = H.num_edges
assert num_planes + num_node_collections + num_edge_collections == len(
ax3.collections
num_edge_collections = 1
num_dyad_collections = 1
num_interlayer_collections = 0

assert (
num_layers
+ num_node_collections
+ num_edge_collections
+ num_interlayer_collections
+ num_dyad_collections
== len(ax3.collections)
)
plt.close()

# custom parameters
pos = xgi.circular_layout(H)
ax4 = xgi.draw_multilayer(
ax4, (node_coll4, edge_coll4) = xgi.draw_multilayer(
H,
pos=pos,
node_fc="red",
node_ec="blue",
node_size=10,
palette="rainbow",
conn_lines_style="dashed",
width=8,
height=6,
h_angle=30,
v_angle=15,
sep=2,
)
sizes = xgi.unique_edge_sizes(H)
num_planes = max(sizes) - min(sizes) + 1
nnum_layers = max(sizes) - min(sizes) + 1
num_node_collections = max(sizes) - min(sizes) + 1
num_edge_collections = H.num_edges
num_thru_lines_collections = 1
num_edge_collections = 1
num_dyad_collections = 1
num_interlayer_collections = 1

assert (
num_planes
num_layers
+ num_node_collections
+ num_edge_collections
+ num_thru_lines_collections
+ num_interlayer_collections
+ num_dyad_collections
== len(ax4.collections)
)

# node_fc
assert np.all(
node_coll4.get_facecolor() == np.array([[1, 0, 0, 1]])
) # red

# node_ec
assert np.all(
node_coll4.get_edgecolor() == np.array([[0, 0, 1, 1]])
) # blue

# node_lw
assert np.all(node_coll4.get_linewidth() == np.array([1]))

# node_size
assert np.all(node_coll4.get_sizes() == np.array([10**2]))


plt.close()


Expand Down
40 changes: 0 additions & 40 deletions tests/drawing/test_draw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
_color_arg_to_dict,
_draw_arg_to_arr,
_interp_draw_arg,
_scalar_arg_to_dict,
)


Expand Down Expand Up @@ -57,45 +56,6 @@ def test_interp_draw_arg(edgelist4):
assert np.allclose(out, np.linspace(1, 11, num=10))


def test_scalar_arg_to_dict(edgelist4):
ids = [1, 2, 3]
min_val = 1
max_val = 5

arg = 1
d = _scalar_arg_to_dict(arg, ids, min_val, max_val)
assert d == {1: 1, 2: 1, 3: 1}

arg = 0.3
d = _scalar_arg_to_dict(arg, ids, min_val, max_val)
assert d == {1: 0.3, 2: 0.3, 3: 0.3}

arg = [0.2, 3, 4]
d = _scalar_arg_to_dict(arg, ids, min_val, max_val)
assert d == {1: 0.2, 2: 3, 3: 4}

arg = np.array([0.2, 3, 4])
d = _scalar_arg_to_dict(arg, ids, min_val, max_val)
assert d == {1: 0.2, 2: 3, 3: 4}

arg = {1: 0.2, 2: 3, 3: 4}
d = _scalar_arg_to_dict(arg, ids, min_val, max_val)
assert d == {1: 0.2, 2: 3, 3: 4}

H = xgi.Hypergraph(edgelist4)
arg = H.nodes.degree
d = _scalar_arg_to_dict(arg, ids, min_val, max_val)
assert d == {1: 1.0, 2: 3.0, 3: 5.0}

with pytest.raises(TypeError):
arg = "2"
d = _scalar_arg_to_dict(arg, ids, min_val, max_val)

with pytest.raises(TypeError):
arg = (1, 2, 3)
d = _scalar_arg_to_dict(arg, ids, min_val, max_val)


def test_color_arg_to_dict(edgelist4):
ids = [1, 2, 3]

Expand Down
796 changes: 0 additions & 796 deletions tutorials/Tutorial 5 - Plotting.ipynb

This file was deleted.

273 changes: 0 additions & 273 deletions tutorials/Tutorial 7 - Convex hulls hypergraph plotting.ipynb

This file was deleted.

Loading