ericmjl / nxviz

Visualization Package for NetworkX
https://ericmjl.github.io/nxviz
MIT License
449 stars 86 forks source link

edge_color and Node_size not changing with keys #248

Open yerraeee opened 6 years ago

yerraeee commented 6 years ago

Description

I was trying to pass attribute keys for costuming node_size and edge_color. However, don't see any changes in the in the plot neither received an error or exception.

What I Did

c_sol_set = nv.CircosPlot(ticket_graph,
    node_color='Resolution_Set_Name', 
    node_grouping = 'Resolution_Set_Name',
    node_order = 'dc',
    node_size = 'dc',
    edge_color='Ticket_Log_Parse.Active_Org',
    node_labels=True,figsize = (15,15) )

c_sol_set.draw()
plt.show()

Paste the command(s) you ran and the output. If there was a crash, please include the traceback here.

image

yerraeee commented 6 years ago
c_sol_set = nv.CircosPlot(ticket_graph,node_color='Resolution_Set_Name', node_grouping = 'Resolution_Set_Name',node_order = 'dc',node_size = 'dc',edge_color='Ticket_Log_Parse.Active_Org',node_labels=True,figsize = (15,15) )

c_sol_set.draw()
plt.show()
yerraeee commented 6 years ago

Also, please let me know if there is a way to change the orientation of labels or adding a custom legend on the plot.

ericmjl commented 6 years ago

Hi @yerraeee, thanks for posting this issue!

I see there are two issues here. The first is the lack of "node size". The second is the lack of "edge colours."

Node sizes

I'm debating with myself on whether node sizes do make sense in a CircosPlot. On one hand, it aesthetically makes sense to keep node sizes equal across nodes. On the other hand, size can convey information, though I have read before (but cannot remember the reference here) that it is roughly as good/bad (in terms of salience) as using colour, and definitely worse than using lines.

From a practical standpoint, computing the node positions with varying node radii might be more complicated than the current implementation (in which I assume constant node size).

For now, due to the reasons above, I'm considering this a bug in the documentation, and not a bug in the implementation, and so I'll do the following:

  1. [ ] Update the docs to highlight the fact that node sizes cannot currently vary with data
  2. [ ] Add a warning for end-users that specifying node_size=... will do nothing, with a link to the docs explaining why.

Edge colours

This is definitely a bug, as edge colours can be meaningful in conveying categorical information. I do have a day job and other commitments, so I will need a bit of time to update the package. Alternatively, if you are willing to take a stab at modifying the codebase (I saw your other issue), I'm more than happy to review a PR from you.

norakassner commented 6 years ago

Hi, Thank you for this very nice and helpful package! I am using it to visualize DNA/RNA bindings. I also need the edge color utility for that and implemented it. It's not completely done but I can commit my updates soon if you are interested. Also I could add examples to visualize on one hand NUPACK outputs (a software to evaluate nucleic acid binding structure) and exact base pair matching between multiple DNA/RNA strands. Nora

ericmjl commented 6 years ago

@noragak your post brought great joy to me! :smile: I would love to accept a PR from you with this contribution, and credit you with implementing it.

Going forward, yours should be the first PR that I accept from someone that's not myself, so in the process of working through this PR with you, I'm hoping to formalize the expectations I've had for myself into a checklist. Let me know if it's too burdensome for you; as the first external contributor, you have the privilege of helping to shape the PR process so that it works for others :smile:.

PR checklist:

  1. [ ] Ensure that the API remains delcarative -- which means your provided implementation should work with edge_color='keyword'. As long as that interface is preserved, I'm not to worried about the underlying implementation.
  2. [ ] If you add functions or methods, do ensure they're tested! That said, if new lines of code are just rendering (i.e. they directly call matplotlib functions), then don't worry too much about them.
  3. [ ] Do remember to add yourself to the Contributors list under AUTHORS.rst!
  4. [ ] I adhere to pycodestyle conventions. They should pass that test.

If you need help anywhere, feel free to post here, ping me on Twitter or send me an email. (If you post here, of course, others will be able to learn from your experience!)

norakassner commented 6 years ago

Hi Eric,

sorry for the late reply. I got sick and wasn't able to continue working on my project. As soon as it is done, I'll let you know and we can start the PR.

Thank you Nora

-----Original-Nachricht----- Betreff: Re: [ericmjl/nxviz] edge_color and Node_size not changing with keys (#248) Datum: 2018-02-09T20:18:55+0100 Von: "Eric Ma" notifications@github.com An: "ericmjl/nxviz" nxviz@noreply.github.com

@noragak https://github.com/noragak your post brought great joy to me! � I would love to accept a PR from you with this contribution, and credit you with implementing it. Going forward, yours should be the first PR that I accept from someone that's not myself, so in the process of working through this PR with you, I'm hoping to formalize the expectations I've had for myself into a checklist. Let me know if it's too burdensome for you; as the first external contributor, you have the privilege of helping to shape the PR process so that it works for others �. PR checklist:

  1. Ensure that the API remains delcarative -- which means your provided implementation should work with edge_color='keyword'. As long as that interface is preserved, I'm not to worried about the underlying implementation.
  2. If you add functions or methods, do ensure they're tested! That said, if new lines of code are just rendering (i.e. they directly call matplotlib functions), then don't worry too much about them.
  3. Do remember to add yourself to the Contributors list under AUTHORS.rst!
  4. I adhere to pycodestyle conventions. They should pass that test. If you need help anywhere, feel free to post here, ping me on Twitter or send me an email http://www.shortwhale.com/ericmjl/ . (If you post here, of course, others will be able to learn from your experience!) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericmjl/nxviz/issues/248#issuecomment-364533041 , or mute the thread https://github.com/notifications/unsubscribe-auth/Ah82YY5k0CMsGXZsTJSknSNJ4qXPLXbGks5tTJoVgaJpZM4RvMWl .

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/ericmjl/nxviz","title":"ericmjl/nxviz","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/ericmjl/nxviz"}},"updates":{"snippets":[{"icon":"PERSON","message":"@ericmjl in #248: @noragak your post brought great joy to me! :smile: I would love to accept a PR from you with this contribution, and credit you with implementing it. \r\n\r\nGoing forward, yours should be the first PR that I accept from someone that's not myself, so in the process of working through this PR with you, I'm hoping to formalize the expectations I've had for myself into a checklist. Let me know if it's too burdensome for you; as the first external contributor, you have the privilege of helping to shape the PR process so that it works for others :smile:. \r\n\r\nPR checklist:\r\n\r\n1. [ ] Ensure that the API remains delcarative -- which means your provided implementation should work with edge_color='keyword'. As long as that interface is preserved, I'm not to worried about the underlying implementation.\r\n1. [ ] If you add functions or methods, do ensure they're tested! That said, if new lines of code are just rendering (i.e. they directly call matplotlib functions), then don't worry too much about them. \r\n1. [ ] Do remember to add yourself to the Contributors list under AUTHORS.rst!\r\n1. [ ] I adhere to pycodestyle conventions. They should pass that test.\r\n\r\nIf you need help anywhere, feel free to post here, ping me on Twitter or send me an email. (If you post here, of course, others will be able to learn from your experience!)"}],"action":{"name":"View Issue","url":"https://github.com/ericmjl/nxviz/issues/248#issuecomment-364533041"}}} 

ericmjl commented 6 years ago

Thanks @noragak! Hope you feel better soon :smile:.

benelot commented 6 years ago

Looking forward to that update too! I realized that both of the mentioned features do not work as expected, even though they are part of the API.

@ericmjl : I think node sizes could still be a great feature, even if it does not always convey proper information. But I think that should also partly be a decision of the user. That depends on your design philosophy if you want to add that or not.

norakassner commented 6 years ago

I pushed it to my repository. How do we proceed?

benelot commented 6 years ago

Now you can go to the repository you forked it from (this one here) and go to the top, there you can start a pull request.

I saw that you pushed your changes to your master branch. That is ok, but now you can not add more pull-requests until your master branch is accepted because your other branches would all include this pull-request.

ericmjl commented 6 years ago

@noragak I've just taken a look at your code, it's beautiful code: commented, adhering to pycodestyle! I have only a few minor requests on the code; please go ahead and submit a Pull Request in so that we can continue the discussion there.

ericmjl commented 6 years ago

@yerraeee edge colours are enabled! Please go ahead and try it out, either by installing from the master branch, from pip, or from conda! With big thanks to @noragak for contributing it in :smile:

selwyth commented 6 years ago

I'm debating with myself on whether node sizes do make sense in a CircosPlot. On one hand, it aesthetically makes sense to keep node sizes equal across nodes. On the other hand, size can convey information, though I have read before (but cannot remember the reference here) that it is roughly as good/bad (in terms of salience) as using colour, and definitely worse than using lines.

Should the node sizes make sense for an ArcPlot (I think yes)? The node sizes did not vary when I tried it out with an ArcPlot. Would like documentation to be updated to say whether node_size is not supported for ArcPlot, or have it be implemented. I can help either way, just curious why it didn't work and what your stance is on node sizes in arc plots.

selwyth commented 6 years ago

Here's how to repro:

networkx version: 2.0 nxviz version: 0.3.6 Python: 3.5.2 Operating System: Linux-4.4.96+-x86_64-with-Ubuntu-16.04-xenial

import networkx as nx
import nxviz

G = nx.DiGraph()

NODES_EBUNCH = [
    ('A', {'n_visitors': '1'}),
    ('B', {'n_visitors': '3'}),
    ('C', {'n_visitors': '4'}),
]

G.add_nodes_from(NODES_EBUNCH)  # use attr_dict if you don't have to vary e.g. color by node

# An ebunch appears to be a list of 2- or 3-tuples
EDGES_EBUNCH = [
    ('A', 'B', 10),
    ('A', 'C', 20),
    ('B', 'C', 250),
    ('C', 'B', 100),
]

G.add_weighted_edges_from(
    EDGES_EBUNCH,
)

c = nxviz.ArcPlot(G, node_labels=True,
                     node_size='n_visitors',
                     node_color='n_visitors',
                     edge_width='weight')
c.draw()

image

Incidentally, looks like node_labels doesn't do anything for ArcPlot too (but does for CircosPlot), will open another issue.

ericmjl commented 6 years ago

@selwyth thanks for the post! From the blog post, node sizes do look like they have some place in ArcPlots.

What are your thoughts - should they be overlapping or not? Aesthetically, it looks a bit messier with overlapping nodes, IMO, but this might just be a matter of taste.

When thinking about variable node sizes with CircosPlots is that computing the right CircosPlot radius would be challenging.

On the other hand, for ArcPlots, the length of the node axis is basically just the sum of diameters of the nodes, if the nodes are not overlapping. If the nodes are overlapping, then it's basically some function of average radius.

I'm happy to accept a PR for node_sizes for ArcPlots, with appropriate docs and examples added in too. I'm also happy to have you decide on the design of the default behaviour (i.e. whether to have overlapping nodes or not). Looking forward to what you've got!

ericmjl commented 6 years ago

@yeraeeee the latest commit in the master branch has rotated node labels! Please do give it a shot and see what you think :smile:.