# Topoplots for visualizing clusters from permutation\_cluster\_1samp\_test

**URL:** <https://mne.discourse.group/t/topoplots-for-visualizing-clusters-from-permutation-cluster-1samp-test/2712>\
**Category:** Support & Discussions\
**Tags:** eeg, visualization\
**Created:** [February 16, 2021, 12:23pm UTC](https://mne.discourse.group/t/topoplots-for-visualizing-clusters-from-permutation-cluster-1samp-test/2712 "2021-02-16T12:23:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MM2123](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mm2123/32/106_2.png) [@MM2123](https://mne.discourse.group/u/MM2123)\
**Post date:** [February 16, 2021, 12:23pm UTC](https://mne.discourse.group/t/topoplots-for-visualizing-clusters-from-permutation-cluster-1samp-test/2712/1 "2021-02-16T12:23:56Z")

</div>

Dear MNE users,

I was wondering if there are some example codes or tutorials for plotting the clusters from the `permutation_cluster_1samp_test` in a topomap. There is a [tutorial](https://mne.tools/stable/auto_tutorials/stats-sensor-space/plot_stats_cluster_1samp_test_time_frequency.html#sphx-glr-auto-tutorials-stats-sensor-space-plot-stats-cluster-1samp-test-time-frequency-py) on plotting TF plot from the output, but I could not find a way to plot topomaps from it.  
Could someone please point me to the right function or tutorial I could follow. Thank you.

Best,  
Manisha

---

<div class="post-metadata">

**Author:** ![pschwenn](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pschwenn/32/22_2.png) [@pschwenn](https://mne.discourse.group/u/pschwenn)\
**Post date:** [February 19, 2021, 12:07am UTC](https://mne.discourse.group/t/topoplots-for-visualizing-clusters-from-permutation-cluster-1samp-test/2712/2 "2021-02-19T00:07:30Z")

</div>

Hi, How about this example [Spatiotemporal permutation F-test on full sensor data](https://mne.tools/stable/auto_tutorials/stats-sensor-space/plot_stats_spatio_temporal_cluster_sensors.html?highlight=f_map) where an f\_map was constructed from the cluster output (T\_obs), and used to create an EvokedArray object so that topo maps could be plotted with the `plot_topomap` function. here is part of the relavent code.

```python
cluster_stats = spatio_temporal_cluster_test(X, n_permutations=1000,
                                             threshold=threshold, tail=1,
                                             n_jobs=1, buffer_size=None,
                                             adjacency=adjacency)

T_obs, clusters, p_values, _ = cluster_stats
good_cluster_inds = np.where(p_values < p_accept)[0]
    f_map = T_obs[time_inds, ...].mean(axis=0)

...
# loop over clusters
for i_clu, clu_idx in enumerate(good_cluster_inds):
    # unpack cluster information, get unique indices
    time_inds, space_inds = np.squeeze(clusters[clu_idx])
    ch_inds = np.unique(space_inds)
    time_inds = np.unique(time_inds)
    # create spatial mask
    mask = np.zeros((f_map.shape[0], 1), dtype=bool)
    mask[ch_inds, :] = True

    # initialize figure
    fig, ax_topo = plt.subplots(1, 1, figsize=(10, 3))

    # plot average test statistic and mark significant sensors
    f_evoked = mne.EvokedArray(f_map[:, np.newaxis], epochs.info, tmin=0)
    f_evoked.plot_topomap(times=0, mask=mask, axes=ax_topo, cmap='Reds',
                          vmin=np.min, vmax=np.max, show=False,
                          colorbar=False, mask_params=dict(markersize=10))

```

Hope that helps,  
Paul
