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

Fix 138: allow xgi.draw to set color of individual nodes or edges #139

Merged
merged 3 commits into from Jul 21, 2022

Conversation

leotrs
Copy link
Collaborator

@leotrs leotrs commented Jul 20, 2022

See #138. Also see attached image, ran from this branch.
2022-07-20-084651_1518x633_scrot

@mcontisc
Copy link
Contributor

This works, yes. However, it still gives problem when you pass an array because the access for arrays is also through node id and not through node position.

@nwlandry
Copy link
Collaborator

nwlandry commented Jul 20, 2022

How about accepting a list or array and mapping indices to nodes like this? (In addition to the dictionary and string methods)

# colors is an input array
nodes = list(H.nodes)
color_dict = {nodes[i]: colors[i] for i in range(H.num_nodes)}

a more succinct way to do that would be color_dict = dict(zip(H.nodes, colors)). This would index the nodes sequentially by the order in which they were added.

@leotrs
Copy link
Collaborator Author

leotrs commented Jul 20, 2022

@nwlandry I actually don't like that one because it would effectively be like accepting a de-facto second node ID. The user can already access the node addition order by just looping over H.nodes.

Wait actually I think I misunderstood what you said. You mean accepting an array like @mcontisc is suggesting, and assuming the order of the colors in the array is the same as the node-addition order, correct? In that case, then yes that's what I was thinking.

@leotrs
Copy link
Collaborator Author

leotrs commented Jul 21, 2022

Done! Now xgi.draw accepts str, dict, or any iterable. If an iterable, the order of the colors in the iterable is assumed to be the same as the order of the nodes in H.nodes. I believe this is what @nwlandry was suggesting, no?
2022-07-21-103153_808x440_scrot

@mcontisc
Copy link
Contributor

Yes, I agree :) Thanks a lot!
Out of curiosity, this is not possible for the hyperedges right? I mean, for coloring them we can only use a colormap. Correct?

@leotrs
Copy link
Collaborator Author

leotrs commented Jul 21, 2022

For now, yes. It would be nice to have a way to override the color assigned to a hyperedge via some other parameter, cc @iaciac.

@nwlandry
Copy link
Collaborator

Looks great!! I think it's ready to merge! I can add the coloring individual edges as an issue.

@leotrs leotrs merged commit fb7d956 into main Jul 21, 2022
@leotrs leotrs deleted the fix-138 branch July 21, 2022 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants