graspologic icon indicating copy to clipboard operation
graspologic copied to clipboard

Networkplot should be able to handle numeric rather than categorical colormapping

Open bdpedigo opened this issue 4 years ago • 2 comments

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 avatar Dec 07 '21 15:12 bdpedigo

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 avatar Dec 07 '21 15:12 bdpedigo

@aj-hersko potential project

bdpedigo avatar Jul 11 '22 14:07 bdpedigo