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

Speedup drawing #173

Merged
merged 4 commits into from
Sep 21, 2022
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
3 changes: 1 addition & 2 deletions tutorials/Tutorial 5 - Plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@
" pos,\n",
" node_size=H.nodes.degree,\n",
" node_lw=H.nodes.degree,\n",
" node_fc=H.nodes.cec_centrality,\n",
" edge_fc=H.edges.node_edge_centrality,\n",
" node_fc=H.nodes.degree,\n",
" ax=ax,\n",
")"
]
Expand Down
13 changes: 6 additions & 7 deletions xgi/drawing/xgi_pylab.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,8 @@ def _scalar_arg_to_dict(arg, ids, min_val, max_val):
elif type(arg) in [int, float]:
return {id: arg for id in ids}
elif isinstance(arg, NodeStat) or isinstance(arg, EdgeStat):
f = lambda val: np.interp(val, [arg.min(), arg.max()], [min_val, max_val])
s = arg.asdict()
return {id: f(s[id]) for id in ids}
vals = np.interp(arg.asnumpy(), [arg.min(), arg.max()], [min_val, max_val])
return dict(zip(ids, vals))
elif isinstance(arg, Iterable):
return {id: arg[idx] for idx, id in enumerate(ids)}
else:
Expand Down Expand Up @@ -420,13 +419,13 @@ def _color_arg_to_dict(arg, ids, cmap):
return {id: arg for id in ids}
elif isinstance(arg, NodeStat) or isinstance(arg, EdgeStat):
if isinstance(cmap, ListedColormap):
f = lambda val: np.interp(val, [arg.min(), arg.max()], [0, cmap.N])
vals = np.interp(arg.asnumpy(), [arg.min(), arg.max()], [0, cmap.N])
elif isinstance(cmap, LinearSegmentedColormap):
f = lambda val: np.interp(val, [arg.min(), arg.max()], [0.1, 0.9])
vals = np.interp(arg.asnumpy(), [arg.min(), arg.max()], [0.1, 0.9])
else:
raise XGIError("Invalid colormap!")
s = arg.asdict()
return {id: np.array(cmap(f(s[id]))).reshape(1, -1) for id in ids}

return {id: np.array(cmap(vals[i])).reshape(1, -1) for i, id in enumerate(ids)}
elif isinstance(arg, Iterable):
return {id: arg[idx] for idx, id in enumerate(ids)}
else:
Expand Down