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

Rewrite draw_hyperedges() #456

Merged
merged 30 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b29d8f9
refact: initial rewrite of draw_hyperedges with collections
maximelucas Aug 22, 2023
4caf84a
updated parameter handling
maximelucas Aug 22, 2023
2fc3b07
attempt at handling color args
maximelucas Aug 22, 2023
c85c22b
fix: alpha
maximelucas Aug 24, 2023
bdf7a48
feature: finished functionality rewrite of drawing hyperedges. style:…
maximelucas Aug 24, 2023
2c05a58
tuto: new on drawing edges
maximelucas Aug 24, 2023
ff7b692
Merge branch 'main' into draw_edges
maximelucas Aug 24, 2023
7923adb
updated docstrings
maximelucas Aug 25, 2023
f8e9b06
fix: tests
maximelucas Aug 25, 2023
99dbfc2
fix: tests and compatbility with draw simplices
maximelucas Aug 25, 2023
349177d
fix: notebooks and order of nodes in lshift
maximelucas Aug 28, 2023
7047d49
added notebook on drawing edges
maximelucas Aug 29, 2023
5f20b0d
fix: impose zorder edges to be below dyads
maximelucas Oct 9, 2023
30d5c8a
reordered edges before plotting to ensure large ones are plotted firs…
maximelucas Oct 9, 2023
2e738e8
fix: import seaborn for cmap crest
maximelucas Oct 9, 2023
deb5d51
reran notebooks
maximelucas Oct 9, 2023
94cd36b
reran notebooks
maximelucas Oct 9, 2023
723d989
reran notebooks
maximelucas Oct 9, 2023
64f459b
Merge branch 'main' into draw_edges
maximelucas Oct 9, 2023
912a279
fix: added seaborn to default requirements
maximelucas Oct 9, 2023
27779d3
fix: updated draw_simplices to make it consistent with draw_hyperedges
maximelucas Oct 16, 2023
0e24377
doc: updated docstrings accordingly
maximelucas Oct 16, 2023
ee380a9
style: black and isort
maximelucas Oct 16, 2023
c3e6c1d
fix: tests
maximelucas Oct 16, 2023
29df5a3
tests: more for draw_hyperedges
maximelucas Oct 16, 2023
6d0a229
style: black
maximelucas Oct 16, 2023
c8b17ad
reran plotting notebooks
maximelucas Oct 16, 2023
172ea73
Fix
nwlandry Oct 16, 2023
f6201dc
merge
maximelucas Oct 16, 2023
4e51373
Merge branch 'draw_edges' of github.com:ComplexGroupInteractions/xgi …
maximelucas Oct 16, 2023
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
29 changes: 13 additions & 16 deletions docs/source/api/tutorials/In Depth 1 - Drawing nodes.ipynb

Large diffs are not rendered by default.

482 changes: 482 additions & 0 deletions docs/source/api/tutorials/In Depth 2 - Drawing hyperedges.ipynb

Large diffs are not rendered by default.

35 changes: 20 additions & 15 deletions docs/source/api/tutorials/XGI in 1 minute.ipynb

Large diffs are not rendered by default.

87 changes: 39 additions & 48 deletions docs/source/api/tutorials/XGI in 15 minutes.ipynb

Large diffs are not rendered by default.

70 changes: 40 additions & 30 deletions docs/source/api/tutorials/XGI in 5 minutes.ipynb

Large diffs are not rendered by default.

98 changes: 58 additions & 40 deletions docs/source/api/tutorials/quickstart.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ scipy>=1.8
pandas>=1.3
networkx>=2.7
requests>=2.0
matplotlib>=3.4
matplotlib>=3.4
seaborn>=0.10
140 changes: 129 additions & 11 deletions tests/drawing/test_draw.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
import numpy as np
import pytest
import seaborn as sb

import xgi
from xgi.exception import XGIError
Expand All @@ -10,13 +11,18 @@ def test_draw(edgelist8):
H = xgi.Hypergraph(edgelist8)

fig, ax = plt.subplots()
ax, node_collection = xgi.draw(H, ax=ax)
ax, collections = xgi.draw(H, ax=ax)

(node_collection, dyad_collection, edge_collection) = collections

# number of elements
assert len(ax.lines) == len(H.edges.filterby("size", 2)) # dyads
assert len(ax.patches) == len(H.edges.filterby("size", 2, mode="gt")) # hyperedges
assert len(ax.lines) == 0
assert len(ax.patches) == 0
offsets = node_collection.get_offsets()
assert offsets.shape[0] == H.num_nodes # nodes
assert len(ax.collections) == 3
assert len(dyad_collection.get_paths()) == 3 # dyads
assert len(edge_collection.get_paths()) == 6 # other hyperedges

# zorder
for line in ax.lines: # dyads
Expand All @@ -27,6 +33,31 @@ def test_draw(edgelist8):

plt.close()

# simplicial complex
S = xgi.SimplicialComplex(edgelist8)

fig, ax = plt.subplots()
ax, collections = xgi.draw(S, ax=ax)
(node_collection, dyad_collection, edge_collection) = collections

# number of elements
assert len(ax.lines) == 0
assert len(ax.patches) == 0
offsets = node_collection.get_offsets()
assert offsets.shape[0] == S.num_nodes # nodes
assert len(ax.collections) == 3

assert len(dyad_collection.get_paths()) == 16 # dyads
assert len(edge_collection.get_paths()) == 3 # other hyperedges

# zorder
for line in ax.lines: # dyads
assert line.get_zorder() == 3
for patch, z in zip(ax.patches, [0, 2, 2]): # hyperedges
assert patch.get_zorder() == z

plt.close()


def test_draw_nodes(edgelist8):

Expand Down Expand Up @@ -198,19 +229,102 @@ def test_draw_hyperedges(edgelist8):
H = xgi.Hypergraph(edgelist8)

fig, ax = plt.subplots()
ax = xgi.draw_hyperedges(H, ax=ax)
ax, collections = xgi.draw_hyperedges(H, ax=ax)
(dyad_collection, edge_collection) = collections
fig2, ax2 = plt.subplots()
ax2, collections2 = xgi.draw_hyperedges(
H, ax=ax2, dyad_color="r", edge_fc="r", dyad_lw=3, dyad_style="--"
)
(dyad_collection2, edge_collection2) = collections2

# number of elements
assert len(ax.lines) == len(H.edges.filterby("size", 2)) # dyads
assert len(ax.patches) == len(H.edges.filterby("size", 2, mode="gt")) # hyperedges
assert len(ax.collections) == 0 # nodes
assert len(ax.lines) == 0
assert len(ax.patches) == 0
assert len(ax.collections) == 2
assert len(dyad_collection.get_paths()) == 3 # dyads
assert len(edge_collection.get_paths()) == 6 # other hyperedges

# zorder
for line in ax.lines: # dyads
assert line.get_zorder() == 3
for patch, z in zip(ax.patches, [2, 2, 0, 2, 2]): # hyperedges
assert patch.get_zorder() == z

# dyad_style
dyad_collection.get_linestyle() == [(0.0, None)]
dyad_collection2.get_linestyle() == [(0.0, [5.550000000000001, 2.4000000000000004])]

# dyad_fc
assert np.all(dyad_collection.get_color() == np.array([[0, 0, 0, 1]])) # black
assert np.all(dyad_collection2.get_color() == np.array([[1, 0, 0, 1]])) # black

# edge_fc
assert np.all(
edge_collection.get_facecolor()[:, -1]
== np.array([0.4, 0.4, 0.4, 0.4, 0.4, 0.4])
)
assert np.all(edge_collection2.get_facecolor() == np.array([[1.0, 0.0, 0.0, 0.4]]))

# edge_lw
assert np.all(dyad_collection.get_linewidth() == np.array([1.5]))
assert np.all(dyad_collection2.get_linewidth() == np.array([3]))
assert np.all(edge_collection.get_linewidth() == np.array([1.0]))

# negative node_lw or node_size
with pytest.raises(ValueError):
ax, collections = xgi.draw_hyperedges(H, ax=ax, dyad_lw=-1)
(dyad_collection, edge_collection) = collections
plt.close()

plt.close("all")


def test_draw_hyperedges_fc_cmap(edgelist8):

H = xgi.Hypergraph(edgelist8)

# default cmap
fig, ax = plt.subplots()
ax, collections = xgi.draw_hyperedges(H, ax=ax)
(dyad_collection, edge_collection) = collections
assert dyad_collection.get_cmap() == plt.cm.Greys
assert edge_collection.get_cmap() == sb.color_palette("crest_r", as_cmap=True)
plt.close()

# set cmap
fig, ax = plt.subplots()
dyad_colors = [1, 3, 5]
ax, collections = xgi.draw_hyperedges(
H, ax=ax, dyad_color=dyad_colors, dyad_color_cmap="Greens", edge_fc_cmap="Blues"
)
(dyad_collection, edge_collection) = collections
assert dyad_collection.get_cmap() == plt.cm.Greens
assert edge_collection.get_cmap() == plt.cm.Blues

plt.colorbar(dyad_collection)
plt.colorbar(edge_collection)

assert (min(dyad_colors), max(dyad_colors)) == dyad_collection.get_clim()
assert (3, 5) == edge_collection.get_clim()
plt.close()

# vmin/vmax
fig, ax = plt.subplots()
ax, collections = xgi.draw_hyperedges(
H,
ax=ax,
dyad_color=dyad_colors,
dyad_vmin=5,
dyad_vmax=6,
edge_vmin=14,
edge_vmax=19,
)
(dyad_collection, edge_collection) = collections
plt.colorbar(dyad_collection)
plt.colorbar(edge_collection)
assert (14, 19) == edge_collection.get_clim()
assert (5, 6) == dyad_collection.get_clim()

plt.close()


Expand All @@ -223,12 +337,16 @@ def test_draw_simplices(edgelist8):
S = xgi.SimplicialComplex(edgelist8)

fig, ax = plt.subplots()
ax = xgi.draw_simplices(S, ax=ax)
ax, collections = xgi.draw_simplices(S, ax=ax)
(dyad_collection, edge_collection) = collections

# number of elements
assert len(ax.lines) == 18 # dyads
assert len(ax.patches) == 3 # hyperedges
assert len(ax.collections) == 0 # nodes
assert len(ax.lines) == 0
assert len(ax.patches) == 0
assert len(ax.collections) == 2

assert len(dyad_collection.get_paths()) == 16 # dyads
assert len(edge_collection.get_paths()) == 3 # other hyperedges

# zorder
for line in ax.lines: # dyads
Expand Down
796 changes: 796 additions & 0 deletions tutorials/Tutorial 5 - Plotting.ipynb

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Loading