ericmjl / nxviz

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

Specify edge_color and node_color? #572

Open whash1234 opened 4 years ago

whash1234 commented 4 years ago

Description

I was wondering if there was any way to manually select the different colors when creating a plot and adding edge_color or node_color to a key/value pair.

In my case, I have 2 different types of edges named 'destination' and have set edge_color = 'destination' which works to color the two types differently, but would prefer a different set of colors than the default colors (in this case greenish/pinkish)

Do you know how to manually define the different colors (maybe even for specific values)?

ericmjl commented 4 years ago

@whash1234 thanks for pinging in :smile:

I can't remember the API clearly at this moment (on mobile and on the move), but I think edge colors can be controlled by one of the keyword arguments that are passed into the CircosPlot constructor. The docs page might have a clue there.

whash1234 commented 4 years ago

Hi I was wondering if you had an update? I still am unable to change the default colors for nodes and edges. Again, I have mapped the nodes to metadata (in this case, 'sentiment') and I wanted to be able to set the colors they get. So, for 'positive' sentiment I would like to set it to green, 'negative' to red, etc. But I cannot find a way to change the default colors it naturally sets these to! They get set as a default to light green / gray and I am unable to change.

ericmjl commented 4 years ago

@whash1234 thanks pinging in again. Now that I’ve read your comment again, I see what you’re trying to do here. Setting a specific color mapping isn’t implemented, as the design of the library didn’t include that in an earlier iteration.

The source code is modifiable, though, and if you look inside the BasePlot constructor from which all other plots inherit, you will see that the setting of node_color happens there. I unfortunately have been swamped with work commitments the past quarter, and looking at what I have on hand going forward, I don’t think I will have time to implement new feature requests that are also properly documented and tested (which is the requirement I have imposed on the library to maintain code quality) in the near-term.

If, however, you’d like to give it a shot at implementing this, I’m open to accepting a pull request, and talking through the codebase if you’d like to attempt implementing this feature - it would be a great win-win for your GitHub profile and for the library. Also it’d be a great contribution back to the community! I’m also trying to encourage more people to make code commons-type of contributions, and happy to guide you through open source dev if you’re not already comfortable with it.

Rabeez commented 4 years ago

@whash1234 I've pushed a branch node_cmap which adds the option to pass a colormap to the plot functions. I'm also busy with work commitments so can't fully test the implementation to add it to master. You can clone the repo and build the relevant branch (look in CONTRIBUTONG.rst for instructions) to get the functionality; let me know if you need help with this.

whash1234 commented 4 years ago

@Rabeez Sorry I have also been caught up at work. How would I go about cloning the repository and building the branch out? I have had little experience in this space in the past couple years. Any help would be appreciated, but this is also not the most urgent issue!

ericmjl commented 4 years ago

@whash1234 thanks for getting back! Let me see, I think I might be able to help with this.

Firstly, create a fork of the nxviz repository to go under your username. It'll be now whash1234/nxviz.

Secondly, create a branch called node_cmap.

Thirdly, create a pull request from ericmjl: nxviz/node_cmap into whash: nxviz/node_cmap, and merge in the changes.

@Rabeez, I think that's the right way to approach this, but if you have a better way to do this, please let me know. @whash1234 I would advise waiting until @Rabeez replies before we go on, but also not to wait too long - if it's the weekend and he hasn't gotten back yet, let's assume that this is the right way to go for now.