nxviz icon indicating copy to clipboard operation
nxviz copied to clipboard

Label for the nodes

Open cjyoon opened this issue 7 years ago • 42 comments

  • 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 avatar Aug 01 '17 04:08 cjyoon

@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.

ericmjl avatar Aug 01 '17 05:08 ericmjl

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 :)

titipata avatar Sep 18 '17 00:09 titipata

Is it possible to use the nx.draw_network_labels function to add node labels to the visualizations produced by nxviz?

basselhak avatar Nov 06 '17 11:11 basselhak

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.

ericmjl avatar Nov 06 '17 12:11 ericmjl

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 avatar Nov 09 '17 12:11 ericmjl

@ericmjl, I tested it and it works for me!

screen shot 2017-11-09 at 10 48 56 am

titipata avatar Nov 09 '17 15:11 titipata

Also working here! Very cool. How would I go about adjusting the positioning so there's no overlap and no label cutoffs?

image

basselhak avatar Nov 10 '17 09:11 basselhak

@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.

ericmjl avatar Nov 10 '17 12:11 ericmjl

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 avatar Nov 10 '17 12:11 basselhak

@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.

ericmjl avatar Nov 10 '17 13:11 ericmjl

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

norakassner avatar Mar 21 '18 11:03 norakassner

bsp bsp1

Some examples to get an impression of my changes

norakassner avatar Mar 21 '18 11:03 norakassner

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!

ericmjl avatar Mar 21 '18 12:03 ericmjl

@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 avatar Mar 21 '18 12:03 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:

bsp2

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.

norakassner avatar Mar 21 '18 13:03 norakassner

@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)

norakassner avatar Mar 21 '18 13:03 norakassner

@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 avatar Mar 21 '18 14:03 ericmjl

@ericmjl I don't have any tests yet. Should I write some prior to the PR?

norakassner avatar Mar 21 '18 15:03 norakassner

@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 avatar Mar 21 '18 16:03 ericmjl

@ericmjl
I'll do the PR tomorrow :)

norakassner avatar Mar 21 '18 16:03 norakassner

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 .

basselhak avatar Mar 22 '18 08:03 basselhak

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?

circosplotnl2

ThijsHrm avatar Apr 13 '18 17:04 ThijsHrm

@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!

ericmjl avatar Apr 13 '18 23:04 ericmjl

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!

ThijsHrm avatar Apr 14 '18 06:04 ThijsHrm

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!

ericmjl avatar Apr 14 '18 15:04 ericmjl

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 avatar Apr 14 '18 20:04 ThijsHrm

@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.

norakassner avatar Apr 16 '18 08:04 norakassner

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

ipv6freely avatar May 16 '18 20:05 ipv6freely

@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:

bsp2

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

ashu16993 avatar Dec 04 '18 17:12 ashu16993

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?

circosplotnl2

How to do this? Please guide

ashu16993 avatar Dec 04 '18 17:12 ashu16993