Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion docs/source/api/drawing/xgi.drawing.draw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ xgi.drawing.draw

.. autofunction:: draw
.. autofunction:: draw_dihypergraph
.. autofunction:: draw_hypergraph_hull
.. autofunction:: draw_multilayer
.. autofunction:: draw_nodes
.. autofunction:: draw_hyperedges
Expand Down
16 changes: 8 additions & 8 deletions docs/source/api/recipes/recipes.ipynb

Large diffs are not rendered by default.

48 changes: 26 additions & 22 deletions docs/source/api/tutorials/In Depth 1 - Drawing nodes.ipynb

Large diffs are not rendered by default.

45 changes: 20 additions & 25 deletions docs/source/api/tutorials/In Depth 2 - Drawing hyperedges.ipynb

Large diffs are not rendered by default.

98 changes: 50 additions & 48 deletions docs/source/api/tutorials/In Depth 3 - Drawing DiHypergraphs.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/maxime/Dropbox (ISI Foundation)/WORK/SCIENCE/xgi/xgi/drawing/draw.py:1658: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored\n",
"/Users/maxime/Dropbox (ISI Foundation)/WORK/SCIENCE/xgi/xgi/drawing/draw.py:1479: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored\n",
" node_collection = ax.scatter(\n"
]
},
Expand Down Expand Up @@ -206,7 +206,7 @@
{
"data": {
"text/plain": [
"<matplotlib.colorbar.Colorbar at 0x17ccdba60>"
"<matplotlib.colorbar.Colorbar at 0x2877d6b50>"
]
},
"execution_count": 6,
Expand Down Expand Up @@ -255,7 +255,7 @@
{
"data": {
"text/plain": [
"<matplotlib.colorbar.Colorbar at 0x17cfe9fd0>"
"<matplotlib.colorbar.Colorbar at 0x2879bc850>"
]
},
"execution_count": 7,
Expand Down Expand Up @@ -597,11 +597,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"id": "2a72b90c",
"metadata": {},
"outputs": [],
"source": []
"source": [
"plt.close(\n",
" \"all\"\n",
") # closes existing ax3d to avoid bugs in next notebooks when running notebook tests"
]
}
],
"metadata": {
Expand Down
592 changes: 280 additions & 312 deletions docs/source/api/tutorials/Tutorial 5 - Plotting.ipynb

Large diffs are not rendered by default.

This file was deleted.

35 changes: 17 additions & 18 deletions tests/drawing/test_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_draw_nodes(edgelist8):
assert np.all(node_collection2.get_linewidth() == np.array([2]))

# node_size
assert np.all(node_collection.get_sizes() == np.array([15**2]))
assert np.all(node_collection.get_sizes() == np.array([7**2]))
assert np.all(node_collection2.get_sizes() == np.array([20**2]))

# zorder
Expand Down Expand Up @@ -362,14 +362,22 @@ def test_draw_hypergraph_hull(edgelist8):
H = xgi.Hypergraph(edgelist8)

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

(node_collection, dyad_collection, edge_collection) = collections

# number of elements
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
assert line.get_zorder() == 3
for patch, z in zip(ax.patches, [2, 2, 0, 2, 2]): # hyperedges
assert patch.get_zorder() == z
assert node_collection.get_zorder() == 4 # nodes
Expand Down Expand Up @@ -410,14 +418,10 @@ def test_draw_multilayer(edgelist8):
assert edge_coll.get_zorder() == 2 # edges

# node_fc
assert np.all(
node_coll.get_facecolor() == np.array([[1, 1, 1, 1]])
) # white
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
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]))
Expand Down Expand Up @@ -499,22 +503,17 @@ def test_draw_multilayer(edgelist8):
)

# node_fc
assert np.all(
node_coll4.get_facecolor() == np.array([[1, 0, 0, 1]])
) # red
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
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 Expand Up @@ -558,7 +557,7 @@ def test_draw_dihypergraph(diedgelist2, edgelist8):
assert np.all(node_coll2.get_linewidth() == np.array([2]))

# node_size
assert np.all(node_coll.get_sizes() == np.array([15**2]))
assert np.all(node_coll.get_sizes() == np.array([7**2]))
assert np.all(node_coll2.get_sizes() == np.array([20**2]))

# edge face colors
Expand All @@ -569,7 +568,7 @@ def test_draw_dihypergraph(diedgelist2, edgelist8):
assert np.all(phantom_node_coll2.get_linewidth() == np.array([2]))

# edge_size
assert np.all(phantom_node_coll.get_sizes() == np.array([15**2]))
assert np.all(phantom_node_coll.get_sizes() == np.array([7**2]))
assert np.all(phantom_node_coll2.get_sizes() == np.array([20**2]))

# line lw
Expand Down
83 changes: 0 additions & 83 deletions tests/drawing/test_draw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import xgi
from xgi.drawing.draw import (
_CCW_sort,
_color_arg_to_dict,
_draw_arg_to_arr,
_interp_draw_arg,
)
Expand Down Expand Up @@ -54,85 +53,3 @@ def test_interp_draw_arg(edgelist4):
arg = np.linspace(0, 10, num=10)
out = _interp_draw_arg(arg, 1, 11)
assert np.allclose(out, np.linspace(1, 11, num=10))


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

# single values
arg1 = "black"
arg2 = (0.1, 0.2, 0.3)
arg3 = (0.1, 0.2, 0.3, 0.5)

# test iterables of colors
arg4 = [(0.1, 0.2, 0.3), (0.1, 0.2, 0.4), (0.1, 0.2, 0.5)]
arg5 = ["blue", "black", "red"]
arg6 = np.array(["blue", "black", "red"])
arg7 = {0: (0.1, 0.2, 0.3), 1: (0.1, 0.2, 0.4), 2: (0.1, 0.2, 0.5)}
arg8 = {0: "blue", 1: "black", 2: "red"}

# test iterables of values
arg9 = [0, 0.1, 0.2]
arg10 = {1: 0, 2: 0.1, 3: 0.2}
arg11 = np.array([0, 0.1, 0.2])

# test single values
d = _color_arg_to_dict(arg1, ids, None)
assert d == {1: "black", 2: "black", 3: "black"}

d = _color_arg_to_dict(arg2, ids, None)
assert d == {1: (0.1, 0.2, 0.3), 2: (0.1, 0.2, 0.3), 3: (0.1, 0.2, 0.3)}

d = _color_arg_to_dict(arg3, ids, None)
for i in d:
assert np.allclose(d[i], np.array([0.1, 0.2, 0.3, 0.5]))

# Test iterables of colors
d = _color_arg_to_dict(arg4, ids, None)
assert d == {1: (0.1, 0.2, 0.3), 2: (0.1, 0.2, 0.4), 3: (0.1, 0.2, 0.5)}

d = _color_arg_to_dict(arg5, ids, None)
assert d == {1: "blue", 2: "black", 3: "red"}

d = _color_arg_to_dict(arg6, ids, None)
assert d == {1: "blue", 2: "black", 3: "red"}

d = _color_arg_to_dict(arg7, ids, None)
assert d == {1: (0.1, 0.2, 0.4), 2: (0.1, 0.2, 0.5)}

d = _color_arg_to_dict(arg8, ids, None)
assert d == {1: "black", 2: "red"}

# Test iterables of values
cdict = {
1: np.array([[0.89173395, 0.93510188, 0.97539408, 1.0]]),
2: np.array([[0.41708574, 0.68063053, 0.83823145, 1.0]]),
3: np.array([[0.03137255, 0.28973472, 0.57031911, 1.0]]),
}
d = _color_arg_to_dict(arg9, ids, cm.Blues)
for i in d:
assert np.allclose(d[i], cdict[i])

d = _color_arg_to_dict(arg10, ids, cm.Blues)
for i in d:
assert np.allclose(d[i], cdict[i])

d = _color_arg_to_dict(arg11, ids, cm.Blues)
for i in d:
assert np.allclose(d[i], cdict[i])

H = xgi.Hypergraph(edgelist4)
arg = H.nodes.degree
d = _color_arg_to_dict(arg, ids, cm.Reds)
assert np.allclose(d[1], np.array([[0.99692426, 0.89619377, 0.84890427, 1.0]]))
assert np.allclose(d[2], np.array([[0.98357555, 0.41279508, 0.28835063, 1.0]]))
assert np.allclose(d[3], np.array([[0.59461745, 0.0461361, 0.07558631, 1.0]]))

# Test bad calls
with pytest.raises(TypeError):
arg = 0.3
d = _color_arg_to_dict(arg, ids, None)

with pytest.raises(TypeError):
arg = 1
d = _color_arg_to_dict(arg, ids, None)
Loading