Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Networkplot should be able to handle numeric rather than categorical colormapping #898

Open
bdpedigo opened this issue Dec 7, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@bdpedigo
Copy link
Collaborator

bdpedigo commented Dec 7, 2021

Currently, the color mapping that happens in networkplot assumes that the variable is categorical, more or less
(see here https://github.com/microsoft/graspologic/blob/690de9b6284441ccaab1d79f08b3718c93d28072/graspologic/plot/plot.py#L1356)

I am used to the seaborn behavior where numeric variables are interpreted as such, and I think we should be able to do the same (i.e. if I want to color nodes by the degree of each node, where darker nodes have higher degree, for example)

The only reason we can't just steal the seaborn way of doing it is because we need the actual palette to be able to color edges as well, and seaborn scatterplot doesn't expose that information as far as I can tell. It was a bit of a hunt to find where it actually happens in seaborn, which is here: https://github.com/mwaskom/seaborn/blob/9425588d3498755abd93960df4ab05ec1a8de3ef/seaborn/_core.py#L71

Compare numeric_mapping and categorical_mapping for an idea of what I mean.

Long story short, I'm not sure how it makes the most sense to implement, but it'd be nice to have in the long term.

@bdpedigo bdpedigo added the enhancement New feature or request label Dec 7, 2021
@bdpedigo
Copy link
Collaborator Author

bdpedigo commented Dec 7, 2021

for now, this is kind of a workaround (if key is the hue variable) to yield a palette outside of networkplot which you can then pass in

levels = list(np.sort(node_data[key].unique()))
cmap = sns.color_palette("Blues", as_cmap=True)
norm = colors.Normalize()
palette = dict(zip(levels, cmap(norm(levels))))

@bdpedigo
Copy link
Collaborator Author

@aj-hersko potential project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant