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

Error with Large Number of Node Colors & Feature Request to Separate Node Color and Node Label #70

Open
hasibagen opened this issue Sep 3, 2024 · 0 comments

Comments

@hasibagen
Copy link

Description: I encountered an issue while plotting nodes with netplotbrain where specifying a large number of different node colors results in errors. Here’s a summary of the issue and my feature requests:

Current Behavior:
My data is :

roi  channel   x   y   z    color
0    Left motor area   10 -45  12  56  #fc8d62
1    Left motor area    4 -50  12  47  #fc8d62
2    Left motor area    1 -57   6  40  #fc8d62
3    Left Broca's area  5 -51  30  33  #8da0cb
4    Left Broca's area  3 -56  25  26  #8da0cb
5    Left Broca's area  2 -60  19  18  #8da0cb
6    Left Broca's area 13 -46  47  21  #8da0cb
7    Left Broca's area  8 -52  41  12  #8da0cb
8    Left Broca's area  7 -55  36   4  #8da0cb
9    Left dorsolateral prefrontal cortex 11 -39  31  48  #fc8d62
10   Left dorsolateral prefrontal cortex 12 -30  28  56  #fc8d62
11   Left dorsolateral prefrontal cortex 18 -20  46  47  #fc8d62
12   Left dorsolateral prefrontal cortex  6 -45  32  41  #fc8d62
13   Left dorsolateral prefrontal cortex 17 -31  49  38  #fc8d62
14   Left dorsolateral prefrontal cortex 20 -12  59  40  #fc8d62
15   Right ventrolateral prefrontal cortex 37  34  67  -2  #66c2a5
16   Right ventrolateral prefrontal cortex 48  48  55   0  #66c2a5
17   Left frontal pole  19 -21  62  29  #ffd92f
18   Left frontal pole  16 -32  62  19  #ffd92f
19   Left frontal pole  27 -13  71  18  #ffd92f
20   Left frontal pole  15 -40  59   9  #ffd92f
21   Left frontal pole  22 -22  71   9  #ffd92f
22   Left frontal pole  23 -13  73  -2  #ffd92f
23   Right frontal pole 35  13  73  -2  #b3b3b3
24   Right frontal pole 36  24  72   9  #b3b3b3
25   Right frontal pole 43  43  60   9  #b3b3b3
26   Right frontal pole 30  13  71  19  #b3b3b3
27   Right frontal pole 41  33  64  19  #b3b3b3
28   Right frontal pole 33  22  63  29  #b3b3b3
29   Left ventrolateral prefrontal cortex  9 -47  52   0  #e78ac3
30   Left ventrolateral prefrontal cortex 21 -33  66  -2  #e78ac3
31   Right dorsolateral prefrontal cortex 42  41  50  29  #e5c494
32   Right dorsolateral prefrontal cortex 31  12  59  39  #e5c494
33   Right dorsolateral prefrontal cortex 34  31  49  39  #e5c494
34   Right dorsolateral prefrontal cortex 45  46  33  43  #e5c494
35   Right dorsolateral prefrontal cortex 32  21  47  49  #e5c494
36   Right dorsolateral prefrontal cortex 39  40  31  48  #e5c494
37   Right Broca's area 50  58  36   4  #66c2a5
38   Right Broca's area 49  54  42  13  #66c2a5
39   Right Broca's area 44  49  48  22  #66c2a5
40   Right Broca's area 53  62  20  19  #66c2a5
41   Right Broca's area 51  58  27  26  #66c2a5
42   Right Broca's area 46  53  31  34  #66c2a5
43   Right motor area  52  60   6  42  #a6d854
44   Right motor area  47  52  12  48  #a6d854
45   Right motor area  40  47  12  56  #a6d854

When plotting with the following code:

netplotbrain.plot(
    nodes=task_roi_mni,
    font="Microsoft Yahei",
    node_color='roi',
    node_type='circles'
)

I receive an error when the number of different colors is large.

Traceback (most recent call last):
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/pandas/core/ops/array_ops.py", line 220, in _na_arithmetic_op
    result = func(left, right)
TypeError: unsupported operand type(s) for -: 'str' and 'str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3550, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-37-ae0da7077c31>", line 1, in <module>
    netplotbrain.plot(
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/netplotbrain/plot.py", line 151, in plot
    node_color = _get_colorby_colors(nodes, node_colorby, **profile)
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/netplotbrain/utils/coloring.py", line 176, in _get_colorby_colors
    cat = (cat - np.nanmin(cat)) / (np.nanmax(cat) - np.nanmin(cat))
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/pandas/core/ops/common.py", line 76, in new_method
    return method(self, other)
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/pandas/core/arraylike.py", line 194, in __sub__
    return self._arith_method(other, operator.sub)
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/pandas/core/series.py", line 5819, in _arith_method
    return base.IndexOpsMixin._arith_method(self, other, op)
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/pandas/core/base.py", line 1381, in _arith_method
    result = ops.arithmetic_op(lvalues, rvalues, op)
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/pandas/core/ops/array_ops.py", line 285, in arithmetic_op
    res_values = _na_arithmetic_op(left, right, op)  # type: ignore[arg-type]
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/pandas/core/ops/array_ops.py", line 229, in _na_arithmetic_op
    result = _masked_arith_op(left, right, op)
  File "/home/jade/anaconda3/envs/fnirs/lib/python3.9/site-packages/pandas/core/ops/array_ops.py", line 184, in _masked_arith_op
    result[mask] = op(xrav[mask], y)
TypeError: unsupported operand type(s) for -: 'str' and 'str'

Changing the code to:

netplotbrain.plot(
    nodes=task_roi_mni,
    font="Microsoft Yahei",
    node_color='color',
    node_colorlegend=True,
    node_type='circles'
)

allows the code to run, but the color legend is not displayed due to the large number of colors.

Feature Request:

Separate Node Color and Node Label Control: I would like to request the ability to separate node color and node label (or name). This would allow one parameter to control the node color and another to control the node label.
Improved Label Arrangement: When the number of labels is large, it would be beneficial to have an option to arrange the labels horizontally or in a more space-efficient manner. If this is already possible using matplotlib, some guidance on how to do so would be appreciated.
Thank you for considering these requests. The ability to customize node color and labels independently would greatly enhance the usability of the plotting functions for complex datasets.

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

No branches or pull requests

1 participant