nxviz
nxviz copied to clipboard
Label for the nodes
- nxviz version: current version as of July 31 2017
- Python version: 3.6
- Operating System: linux
Description
Is there a way for labels for the nodes to show up in the plot?
Thanks!
@cjyoon at the moment no, as the package wasn't intended for this - when visualizing large graphs, the labels may clutter up the visual, which is why I haven't implemented this.
However, if you're interested in contributing, I'm happy to discuss with you how it might be implemented, leading up to a pull request from you into the repository! Let me know if this is something that you'd like to take a stab at.
Hi @ericmjl, great library. I start using it from your class. Just want to +1 for implementing node_labels
. This feature will be really useful to visualize small network :)
Is it possible to use the nx.draw_network_labels function to add node labels to the visualizations produced by nxviz?
At the moment, not yet possible. However, I'm looking into this. Earlier on when I developed nxviz
, I was less proficient with matplotlib
's text capabilities, but I'm starting to feel a bit more confident now, so I think this can be added in short order.
ping @basselhak, @titipata & @cjyoon - I have just pushed up to master this feature request. Currently only worked out for CircosPlots. Could you all download it and give it a shot? (It's not yet released to PyPI or conda-forge, because I haven't written the tests necessary for this yet.)
@ericmjl, I tested it and it works for me!

Also working here! Very cool. How would I go about adjusting the positioning so there's no overlap and no label cutoffs?
@basselhak Hmm, it's probably going to need some matplotlib tweaking underneath the hood.
Can you try the following line (I have highlighted it with a comment) to see if it works to adjust the figure boundaries?
c = CircosPlot(......)
c.draw()
c.figure.tight_layout() # this is the key line to add
plt.draw()
If it works (with possibly some image distortion), then I'll go back and figure out how to design the API to automate that portion. If it doesn't, I'll have to see if something else can be done.
Also, just wondering if you send me the CSV file + code that you used to generate the figure? That'll help me prototype with a bit more interactivity.
Hi @ericmjl , you should be able to access the data and code through this github repo: https://github.com/basselhak/braindrain
I just tried it out myself, and it doesn't seem to change the layout. Thanks for looking into this.
@basselhak thanks for giving that a shot. Good to know, I can rule out that hypothesis then. This might take a bit more hacking than I originally thought.
Hi Eric, in the last week I added a few more changes locally. One is about the node labels: I changed it up a bit and if you are interested I would do another pull request. In my current version you can decide for each node if you want labels to be displayed or not. Also the color of the label can be set to the colors of the nodes or left black. Is that something you would like to integrate in your plotting tool?
What I am working on right now is that you can set the displayed text of the labels outside. Here, I haven't decided on the best way to implement it. A nice idea from your side?
Unrelated to this issue: I also extended the number of groups to >8. That wasn't possible before.
Its all not on my repo yet. Let me know if you are interested in changing those features!
Thanks again for the nice package Nora
Some examples to get an impression of my changes
Hi @noragak, great to hear from you again! :smile:
Here are my responses:
in the last week I added a few more changes locally. One is about the node labels: I changed it up a bit and if you are interested I would do another pull request. In my current version you can decide for each node if you want labels to be displayed or not. Also the color of the label can be set to the colors of the nodes or left black. Is that something you would like to integrate in your plotting tool?
Yes - Let's get that in! Do make sure that the API remains declarative. :smile:
What I am working on right now is that you can set the displayed text of the labels outside. Here, I haven't decided on the best way to implement it. A nice idea from your side?
I see that the labels are like "node group" labels, rather than individual node labels, is that right? This is something I would also love to see, and depending on the code, I think I will leverage the implementation for ArcPlots as well.
Unrelated to this issue: I also extended the number of groups to >8. That wasn't possible before.
Great stuff! What was the key change that enabled this? Was it the use of a different colour map?
Its all not on my repo yet. Let me know if you are interested in changing those features!
Definitely this would be a great enhancement to nxviz! Please do send in a PR and let's work through it together!
@basselhak on the latest version of master, rotated node labels for CircosPlots are available. Please give it a shot! Big thanks to @cdeiner for the implementation!
@ericmjl Sorry the plot was misleading! Its actually node labels. So instead of one boolean for the labels you have a boolean array indicating which node should carry the label. By setting True only in the middle of each group, you end up with group labels. Otherwise you can have something like that:
Now I will add something to optionally set the list of labels outside CircosPlot. This way you can change the labels after the network G is already built.
@ericmjl
"Great stuff! What was the key change that enabled this? Was it the use of a different colour map?"
Yes I kept yours but if more >8 groups should be displayed it changes to an other color pallet (maybe colors should be shuffled internally because similar colors are next to each other right now)
@noragak
Sorry the plot was misleading! Its actually node labels.
Ah got it!
So instead of one boolean for the labels you have a boolean array indicating which node should carry the label. By setting True only in the middle of each group, you end up with group labels.
Selectively enabling node labels would be awesome :smile:. Let's see what the PR looks like!
Yes I kept yours but if more >8 groups should be displayed it changes to an other color pallet (maybe colors should be shuffled internally because similar colors are next to each other right now)
For now, I'm very satisfied with what I see for the color scheme. Let's hold off on shuffling the colours to see if there's anything generalizable to ArcPlots. What do you think?
@ericmjl I don't have any tests yet. Should I write some prior to the PR?
@noragak I think it should be okay to submit the PR first, and then add tests along the way.
Later on, I plan on adding in matplotlib testing as well - this will help with integration testing. But for now, don't worry about it :smile:
@ericmjl
I'll do the PR tomorrow :)
Great! I look forward to trying it out.
2018-03-21 13:56 GMT+01:00 Eric Ma [email protected]:
@basselhak https://github.com/basselhak on the latest version of master, rotated node labels for CircosPlots are available. Please give it a shot! Big thanks to @cdeiner https://github.com/cdeiner for the implementation!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericmjl/nxviz/issues/75#issuecomment-374927122, or mute the thread https://github.com/notifications/unsubscribe-auth/Ab8nN2YpdkTm3jNGeSUSgeSML0c0c8i-ks5tgk4DgaJpZM4OpOnf .
Hey guys, as I was working on my own project I implemented the following solution for overlapping node labels: numbering them and putting them ordered around the circos. Is there interest in having this solution alongside rotated labels?
@ThijsHrm this would be a wonderful contribution! Yes, I would love to accept this as a PR.
I would like to organize the label layout choices in the PR as well, particularly related to how we can name them and expose them in a declarative way to the end-user. Would love your input - let's see what comes in the PR!
As for layout choices, it might make sense to replace the rotate_labels(Bool) function with label_layout(None/String) with string options 'rotate' and 'numbers'. Something along those lines? Also, it might be a good idea to increase the comments and break the label_nodes function down into 2 or 3 smaller components at this point to keep the code maintainable. @noragak, are you currently actively working on the functions? If so what do you think?
My access to a computer is currently limited but I hope to get to it by monday!
As for layout choices, it might make sense to replace the rotate_labels(Bool) function with label_layout(None/String) with string options 'rotate' and 'numbers'. Something along those lines?
Yes, this definitely make sense. Leaving a note here for both of us, let's make sure that the docstring is updated appropriately as well.
Also, it might be a good idea to increase the comments and break the label_nodes function down into 2 or 3 smaller components at this point to keep the code maintainable.
Great stuff, sounds like a good idea!
Correction: in the previous post I was refering to parameters of the init method of the circosplot, not 'functions'. Appologies for the poor phrasing.
@ThijsHrm right now I am not working further on the plots but I agree with you that those are nice adds. I'll let you guys know if I continue working on the project.
What about a small change so that the label is in the node, rather than a number with an outside label? If the figsize
is large enough this should be able to accommodate. Thoughts? @ThijsHrm @ericmjl
@ericmjl Sorry the plot was misleading! Its actually node labels. So instead of one boolean for the labels you have a boolean array indicating which node should carry the label. By setting True only in the middle of each group, you end up with group labels. Otherwise you can have something like that:
Now I will add something to optionally set the list of labels outside CircosPlot. This way you can change the labels after the network G is already built.
Has this chart been committed to the package? May I get a sample code on how to implement to implement this? Thank you
Hey guys, as I was working on my own project I implemented the following solution for overlapping node labels: numbering them and putting them ordered around the circos. Is there interest in having this solution alongside rotated labels?
How to do this? Please guide