Open cjyoon opened 7 years ago
@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 notifications@github.com:
@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
@ashu16993 to do this, pass in a value to the kwarg node_labels
. The value should be the key of some metadata that is attached to each node.
@ericmjl Thanks for the quick reply! I am passing a key of my metadata, but I still am not getting the legend. Even my node labels overlap. Needed help with that.
c = CircosPlot(G,node_grouping="class",
node_color="class",
node_order="class",
node_labels="class",
group_label_position="middle",
nodeprops ={"radius":5},
node_label_layout="rotation",
group_label_color=True,figsize = (25,25))
c.draw()
plt.tight_layout(rect=(0.5, 0.5, 0.5, 0.5))
plt.show()
For the legend, that was something custom that @ThijsHrm implemented.
It appears your node labels are fine; it's the group labels for which there are issues.
@ThijsHrm, would you be open to sharing code illustrating how you did the custom legend?
@ericmjl Is there any way to pull the group labels a fit farther away as they are getting covered by the node labels, also can i change the font and font-size?
@ashu I'm not sure at the moment, as I don't have the source code on the tip of my fingers. I am, however, quite busy with my own work at the moment; if you have the motivation and need to do so, please feel free to dig into the source to see what you might glean. That is, after all, one of the premises of open source software!
@ericmjl I got how to change the position of the labels, their font and fontsize. Now I am trying to add a gap between two groups of nodes, to make it easier to read. If you remember from where should I start looking to make those changes, please let me know. It will be of great help!
add a gap between two groups of nodes
As far as I know, this is not possible, as the layout algorithm underneath the hood places each node along the circumference of a circle. To separate them based on groups would require a re-computation of the node positions, which at this point, is not done. However, I am open to a PR that enables this as an option.
Some examples to get an impression of my changes
Hi @noragak, I wish to make my edges the way you have made in your graph, distinguishable. Will you be open to sharing your code on how you achieved it? Thanks!!
add a gap between two groups of nodes
As far as I know, this is not possible, as the layout algorithm underneath the hood places each node along the circumference of a circle. To separate them based on groups would require a re-computation of the node positions, which at this point, is not done. However, I am open to a PR that enables this as an option.
Hey @ericmjl,
I am working on the functionality of editing font, font-size of all the texts in the graphs and also on adding space between two groups of nodes. If you are open to adding those functionalities, I shall make a pull request once completed.
Great package by the way!
@ashu16993 that sounds great! Yes, open to a PR. I would advise making each of the following a separate PR, to make things easier to review:
Using those titles, and referencing this thread, will definitely help jog my memory.
When you put in a PR, don't forget to do a number of things:
examples/
directory (you can generate fake graphs if needed)nxviz
. Do try to mimic the code style; this also motivates small PRs, as it's easier to check for code style.
Btw, pardon me if I came across as being grumpy and terse in my replies above, I was knee-deep in deep work when I read the thread. It helps lift up my spirits when I hear feedback that the package is useful for others, so thanks for the feedback!
@ericmjl Thanks for the quick reply! I am passing a key of my metadata, but I still am not getting the legend. Even my node labels overlap. Needed help with that.
c = CircosPlot(G,node_grouping="class", node_color="class", node_order="class", node_labels="class", group_label_position="middle", nodeprops ={"radius":5}, node_label_layout="rotation", group_label_color=True,figsize = (25,25)) c.draw() plt.tight_layout(rect=(0.5, 0.5, 0.5, 0.5)) plt.show()
Hey Guys, I'm working with nxviz CircosPlot and have been trying to figure out how to turn my node labels according to a node attribute. I'm trying to build a graph of brain areas, so would be much better to have the names itself. Was there a solution for this?
@eduardacenteno preprocessing your graph, at the moment, seems to be the right way to handle this.
One of our contributors, @ThijsHrm, contributed an example that might show you how to handle it. https://github.com/ericmjl/nxviz/blob/master/examples/circos/rotate_labels.py
I was reminded from this PR.
Description
Is there a way for labels for the nodes to show up in the plot?
Thanks!