paulcbogdan / NiChord

Package for visualizing brain networks. Creates chord diagrams drawn using matplotlib
MIT License
75 stars 7 forks source link

[Feature Request] Introduce a parameter similar to `edge_threshold` in `nilearn.plotting.plot_connectome` for `plot_glassbrain` and `plot_and_combine` #3

Closed AngusMonroe closed 5 months ago

AngusMonroe commented 5 months ago

Hello,

I've been exploring the functionalities of NiChord and find it extremely useful for my research. As I'm preparing to use it to generate figures for my paper, I encountered an issue while using a connectivity matrix to generate edges for plot_glassbrain.

Currently, when using a connectivity matrix, I find that the resulting glass brain visualization contains too many edges, making it difficult to interpret. It would be very helpful if a parameter similar to edge_threshold in nilearn.plotting.plot_connectome could be introduced to filter the edges by their weight.

This would enable users to control the density of the edges in the glass brain, making the visualization more comprehensible and suitable for publication.

Thank you for considering this enhancement.

paulcbogdan commented 5 months ago

Thanks for your note. This seems like a fine idea. Too many papers nowadays plot diagrams with endless numbers of connections that are obviously impossible to read. I will look into implementing this, or if you feel up to it, feel free to make a pull request.

For now, what you could do is simply loop over your edge_weights list and set those below some value to zero:

threshold = 0.2 # change to whatever you want
f = lambda x: 0 if x < threshold else x
edge_weights = [f(x) for x in edge_weights]

Weights at zero shouldn't show up in the glass brain or chord diagram.

AngusMonroe commented 5 months ago

Hi, Paul,

Thank you for your prompt reply. In addition to simply looping over edge_weights list with a threshold, I need also manually pass vmin and vmax to plot_glassbrain() in case it computes them from edge_weights, which will destroy the consistency for edge color between glass brain and the chord diagram.

Moreover, for the chord diagram, edges with 0 weight will still be plotted out. So looping over edge_weights list with a threshold could not meet the requirement. I will keep looking for a solution. Please let me know if you have further suggestions.

paulcbogdan commented 5 months ago

I see, I just updated the package. plot_chord and plot_glassbrain should now be able to take an edge_threshold argument that works the same as in nilearn (float or percentile string like "25.3%")

AngusMonroe commented 5 months ago

It works well for me. Thank you so much, Paul.