0

I am attempting to create a chord diagram using plot_connectivity_circle from mne_connectivity.viz library.

My data is similar to the following, where letter and number represent separate nodes and count represents the number of connections between those nodes:

import random
import string
random.seed(10)

df = pd.DataFrame({'letter':[random.choice(string.ascii_lowercase) for x in range(20)],
                  'number':[str(random.randint(0,22)) for x in range(20)],
                  'Count':[random.randint(20,50) for x in range(20)]})

dataframe

The documentation for mne cites examples in which a square matrix of connectivity scores is used to create the chord diagram which differs from my use case.

However, it also states that a 1d matrix can be used for the connectivity scores if arrays of indices are also passed that correspond to the correct list of node names. Therefore I assume that df.Count can be used to represent the connectivity scores?

Given my data, I can't figure how to pass the relevant data to the node_names and indices arguments in the correct order and would appreciate some guidance please!


For reference, I have achieved a similar visualisation using the holoviews library but find the options for customisation to be lacking. Code and output for that visualisation included below as an example:

import numpy as np
import holoviews as hv
from holoviews import opts, dim
hv.extension('bokeh')
hv.output(size=350)

nodes = list(set(df['letter'].tolist() + df['number'].tolist()))
nodes = hv.Dataset(pd.DataFrame(nodes, columns=['node']))

chord = hv.Chord((df, nodes))
chord.opts(
    opts.Chord( 
               labels = 'node', label_text_font_size='12pt', 
               node_color='node', node_cmap='Category20', node_size=10, 
               edge_color='number', edge_cmap='Category20', edge_alpha=0.9, edge_line_width=1)
) 

example_viz

r0bt
  • 383
  • 3
  • 12

1 Answers1

1

For the record, I have found an acceptable solution to this issue.

I returned to the original data (the above was the result of groupby and count to get df.Count values) and used crosstab() to generate a dataframe containing the connectivity scores. I referred to the answer to this post for direction

I then transformed the result to an adjacency matrix using to_numpy() which could be passed to the con argument for plot_connectivity_circle().

A list of the columns from the crosstab() can then be passed to the node_names argument.

I don't have time to post a working example of my code right now but will hopefully find time later.

If anyone knowledgeable in the use of mne and plot_connectivity_cirlce can help answer the original question given the data in the form described in the original post, I'd be very interested to learn how it is done!

r0bt
  • 383
  • 3
  • 12