Skip to content

Commit

Permalink
Fix #480 (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry authored Oct 25, 2023
1 parent 536f592 commit 16e39f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
9 changes: 6 additions & 3 deletions docs/source/api/recipes/recipes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@
}
],
"source": [
"edge_color = [colors[i-2] for i in H.edges.filterby(\"order\", 1, \"gt\").size.aslist()]\n",
"edge_color = [colors[i - 2] for i in H.edges.filterby(\"order\", 1, \"gt\").size.aslist()]\n",
"\n",
"xgi.draw(H, pos=pos, dyad_color=link_color, edge_fc=edge_color);"
]
Expand Down Expand Up @@ -661,7 +661,7 @@
}
],
"source": [
"color_dict = {idx : colors[i-2] for idx, i in H.edges.size.asdict().items()}\n",
"color_dict = {idx: colors[i - 2] for idx, i in H.edges.size.asdict().items()}\n",
"\n",
"xgi.draw(H, pos=pos, dyad_color=color_dict, edge_fc=color_dict);"
]
Expand Down Expand Up @@ -692,9 +692,12 @@
],
"source": [
"from matplotlib.colors import ListedColormap\n",
"\n",
"cmap = ListedColormap(colors[1:])\n",
"\n",
"_, (node_collection, dyad_collection, edge_collection) = xgi.draw(H, pos=pos, dyad_color=link_color, edge_fc_cmap=cmap)\n",
"_, (node_collection, dyad_collection, edge_collection) = xgi.draw(\n",
" H, pos=pos, dyad_color=link_color, edge_fc_cmap=cmap\n",
")\n",
"\n",
"plt.colorbar(edge_collection, label=\"edges\")\n",
"\n",
Expand Down
10 changes: 3 additions & 7 deletions docs/source/api/tutorials/In Depth 2 - Drawing hyperedges.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,16 @@
],
"source": [
"ax, (dyad_collection, edge_collection) = xgi.draw_hyperedges(\n",
" H,\n",
" pos=pos,\n",
" dyad_color=[3, 1, 4],\n",
" edge_fc=H.edges.size)\n",
" H, pos=pos, dyad_color=[3, 1, 4], edge_fc=H.edges.size\n",
")\n",
"\n",
"ax, node_collection = xgi.draw_nodes(H, pos=pos, node_fc=H.nodes.degree, zorder=3)\n",
"\n",
"plt.colorbar(node_collection, label=\"nodes\")\n",
"plt.colorbar(dyad_collection, label=\"dyads\")\n",
"plt.colorbar(edge_collection, label=\"edges\")\n",
"\n",
"plt.tight_layout()\n",
"\n",
" "
"plt.tight_layout()"
]
}
],
Expand Down
12 changes: 12 additions & 0 deletions tests/core/test_hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,18 @@ def test_set_edge_attributes(edgelist1):
H3.set_edge_attributes({"test": {2: "weight"}})


def test_480(edgelist1):
H1 = xgi.Hypergraph(edgelist1)
attr_dict1 = {
0: 1,
1: 2,
2: 3,
3: -1,
}
H1.set_edge_attributes(attr_dict1, "weight")
assert H1.edges.attrs("weight").asdict() == attr_dict1


def test_cleanup():
H = xgi.Hypergraph()
H.add_edges_from([["a", "b", "c"], ["a", "b", "c"], ["e", "f"]])
Expand Down
2 changes: 1 addition & 1 deletion xgi/core/hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def set_edge_attributes(self, values, name=None):
try:
for e, value in values.items():
try:
self._edge_attr[id][name] = value
self._edge_attr[e][name] = value
except IDNotFound:
warn(f"Edge {e} does not exist!")
except AttributeError:
Expand Down

0 comments on commit 16e39f6

Please sign in to comment.