xgi icon indicating copy to clipboard operation
xgi copied to clipboard

`rescale_sizes` doesn't work for numerical inputs

Open nwlandry opened this issue 10 months ago • 3 comments

Minimal working example:

import xgi
H = xgi.Hypergraph([[1, 2, 3]])
nodal_property = [-1, 0, 1]
xgi.draw(H, node_size=nodal_property, rescale_sizes=True)

gives the error ValueError: node_size cannot contain negative values. We should make this consistent with how xgi handles nodestats, i.e., interpolating them between max and min values.

nwlandry avatar Apr 02 '24 15:04 nwlandry

Do you mean that you would like the -1 to be rescaled to a positive value? I feel like any negative value for a node size is wrong and should raise an error rather than be rescaled, but happy to be convinced.

maximelucas avatar Apr 05 '24 10:04 maximelucas

Maybe a work-around solution would be to publish a recipe detailing how to take a list of nodal values (In my case, continuous values between -1 and 1) and mapping them to node sizes. I probably would do something like

import xgi
import numpy as np
min_node_size = 1
max_node_size = 30

H = xgi.Hypergraph([[1, 2, 3]])
props = np.random.uniform(-1, 1, H.num_nodes)
node_size = np.interp(props, [props.min(), props.max()], [min_node_size, max_node_size])
xgi.draw(H, node_size=node_size)

nwlandry avatar Apr 09 '24 13:04 nwlandry

Yea we can probably do that. My feeling is that I would probably rather visualize that by having colored nodes with a diverging colormap to visualize positive and negative values. What's your exact use case? An interpolation recipe is useful in any case I would say.

maximelucas avatar Apr 09 '24 18:04 maximelucas