# Subplotting plot\_connectivity\_circle

**URL:** <https://mne.discourse.group/t/subplotting-plot-connectivity-circle/4720>\
**Category:** Support & Discussions\
**Created:** [April 16, 2022, 7:51pm UTC](https://mne.discourse.group/t/subplotting-plot-connectivity-circle/4720 "2022-04-16T19:51:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![szerfas1](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/szerfas1/32/1156_2.png) [@szerfas1](https://mne.discourse.group/u/szerfas1)\
**Post date:** [April 16, 2022, 7:51pm UTC](https://mne.discourse.group/t/subplotting-plot-connectivity-circle/4720/1 "2022-04-16T19:51:19Z")

</div>

- MNE version: 1.0
- MNE-connectivity version: 0.3
- operating system: macOS Monterey M1

I’d like to plot multiple connectivity circles on a single figure. Each circle is produced via `plot_connectivity_circle`. The docs imply this is possible, but I’ve not been able to get multiple attempts to work.

My first attempt seeks to make use of the `ax` kwarg listed in the `plot_connectivity_circle` [docs](https://mne.tools/mne-connectivity/dev/generated/mne_connectivity.viz.plot_connectivity_circle.html#:~:text=accommodate%20long%20labels.-,ax,-%3A%20instance%20of%20matplotlib). But I get the following error:

```python
TypeError Traceback (most recent call last)
Input In [66], in <cell line: 50>()
     31 # TODO: use different color scheme to not mislead with less connectivity
     32 plot_connectivity_circle(
     33 conn_diff,
     34 node_names=ch_names,
   (...)
     48 n_lines=n_sig,
     49 )
---> 50 plot_conn_diff_circles('J2', seg_connectivity['J2'], 'J1', seg_connectivity['J1'], perm_thresholds)

Input In [66], in plot_conn_diff_circles(name1, conn1, name2, conn2, perm_thresholds)
     29 ax = axs[row][col]
     31 # TODO: use different color scheme to not mislead with less connectivity
---> 32 plot_connectivity_circle(
     33 conn_diff,
     34 node_names=ch_names,
     35 facecolor='grey',
     36 textcolor='black',
     37 linewidth=1, 
     38 colormap='bwr',
     39 fontsize_names=8,
     40 padding=2,
     41 fontsize_colorbar=8,
     42 title=f'{band_name} {conn_method}, {name1} - {name2}',
     43 # fig=fig,
     44 # ax is in the docs but throws a KeyError -- I'm on version 0.3 and it does not yet accept ax kwarg
     45 ax=ax,
     46 # subplot=(row+1,col+1,1),
     47 node_angles=node_angles,
     48 n_lines=n_sig,
     49 )

TypeError: plot_connectivity_circle() got an unexpected keyword argument 'ax'

```

Despite being on MNE-connectivity version 0.3, which I believe is the most recent stable release:

So I tried to make use of the kwargs `fig` and `subplot`, which the docs say are soon to be deprecated, but should at least still work. This code runs, and appears to put colorbars throughout the figure, but only ever overwrites the first subplot:

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/6/67d490af828292dc6671ffa2528a6eabe8e1ae7e.jpeg)

Code here:

```python
from mne_connectivity.viz import plot_connectivity_circle
from mne_connectivity import Connectivity

def plot_conn_diff_circles(name1: str, conn1: Connectivity, name2: str, conn2: Connectivity, perm_thresholds: List[float]):

    node_angles = np.linspace(0, 180, len(ch_names))
    node_angles[[3, 4]] = [180-205, 205] # TODO: change to swap left and right

    # TODO: set bands globally
    bands = ['Delta', 'Theta', 'Alpha', 'Beta', 'Gamma']
    
    n_bands = len(bands)
    n_col = math.ceil(math.sqrt(n_bands))
    n_row = math.ceil(n_bands / n_col)
    fig, axs = plt.subplots(n_row, n_col)
    
    for band_idx, band_name in enumerate(bands):
        
        conn_diff = conn1.get_data(output='dense')[:, :, band_idx] - conn2.get_data(output='dense')[:, :, band_idx]
        # TODO: refactor to make more clear
        perm_th = list(perm_thresholds.values())[band_idx]
        conn_diff[np.abs(conn_diff) < perm_th] = 0 # Ideally, delete non-sig conns instead and change below plot to 1D array
        n_sig = len(conn_diff[conn_diff!=0])
        
        col = int(band_idx % n_col)
        row = int(math.floor(band_idx / n_col))
        ax = axs[row][col]
        
        # TODO: use different color scheme to not mislead with less connectivity
        plot_connectivity_circle(
            conn_diff,
            node_names=ch_names,
            facecolor='grey',
            textcolor='black',
            linewidth=1, 
            colormap='bwr',
            fontsize_names=8,
            padding=2,
            fontsize_colorbar=8,
            title=f'{band_name} {conn_method}, {name1} - {name2}',
            fig=fig,
            # ax is in the docs but throws a TypeError -- I'm on version 0.3 and it does not yet accept ax kwarg
# ax=ax,
            subplot=(row+1,col+1,1),
            node_angles=node_angles,
            n_lines=n_sig,
        )
plot_conn_diff_circles('J2', seg_connectivity['J2'], 'J1', seg_connectivity['J1'], perm_thresholds)

```

This appears related to [this question](https://mne.discourse.group/t/how-to-subplot-figure-from-plot-connectivity-circle/3391), but the solution there involves a hacky workaround I don’t think is implied by the docs (redrawing multiple figures, then examining the Canvas buffer and using the raw data to produce a png).

---

<div class="post-metadata">

**Author:** ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)\
**Post date:** [April 16, 2022, 8:11pm UTC](https://mne.discourse.group/t/subplotting-plot-connectivity-circle/4720/2 "2022-04-16T20:11:10Z")

</div>

Hi @szerfas1,

the error you see tells you that in your version of mne\_connectivity the `plot_connectivity_circle` function does not have an `ax` argument. You say you are on 0.3 version, but the ax argument was added later - you must have been reading the docs for the development version. This is the link to the 0.3 docs for this function:  
[https://mne.tools/mne-connectivity/stable/generated/mne\_connectivity.viz.plot\_connectivity\_circle.html](https://mne.tools/mne-connectivity/stable/generated/mne_connectivity.viz.plot_connectivity_circle.html)

---

<div class="post-metadata">

**Author:** ![szerfas1](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/szerfas1/32/1156_2.png) [@szerfas1](https://mne.discourse.group/u/szerfas1)\
**Post date:** [April 16, 2022, 9:09pm UTC](https://mne.discourse.group/t/subplotting-plot-connectivity-circle/4720/3 "2022-04-16T21:09:10Z")

</div>

Thanks Mikolaj. I bet I was on the wrong documentation, but that documentation still suggests subplot should work, right? Am I missing something else?

---

<div class="post-metadata">

**Author:** ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)\
**Post date:** [April 17, 2022, 6:03am UTC](https://mne.discourse.group/t/subplotting-plot-connectivity-circle/4720/4 "2022-04-17T06:03:29Z")

</div>

You were using an `ax` argument, which does not exist in version 0.3 of the function. The `subplot` argument is present.

---

<div class="post-metadata">

**Author:** ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)\
**Post date:** [April 17, 2022, 6:06am UTC](https://mne.discourse.group/t/subplotting-plot-connectivity-circle/4720/5 "2022-04-17T06:06:12Z")

</div>

The easiest fix for you to try is to install the dev version of mne\_connectivity.

---

<div class="post-metadata">

**Author:** ![szerfas1](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/szerfas1/32/1156_2.png) [@szerfas1](https://mne.discourse.group/u/szerfas1)\
**Post date:** [April 18, 2022, 9:08pm UTC](https://mne.discourse.group/t/subplotting-plot-connectivity-circle/4720/6 "2022-04-18T21:08:23Z")

</div>

Excellent, that works nicely. It may be nice to learn how to do this with the old kwargs for backwards compatibility, but I think I’ll be able to get this to work nicely.
