How to plot z-scores using plot_topomap?

Hi all,

I would like to plot a gradiometer topography of z-scores using plot_topomap.
How can I override the function’s automatic scaling?

Thank you,

Ana P

Hi @anapesq , I’m not clear where you are stuck. have you actually been able to plot a topomap of the zscores? If not, the code below should help you to get closer. And plot_topomap accepts a vlim parameter, where you can set the min and max colorbar values (if that is what you mean by automatic scaling).

(not tested)

import mne
import scipy

# Load the data
fname = mne.datasets.sample.data_path() / "MEG" / "sample" / "sample_audvis_raw.fif"
raw = mne.io.read_raw(fname)
raw.pick("grad")
data = raw.get_data()  # shape (n_channels, n_times)

# compute z-score across channels for each sample and average across time, such that there is 1 z-score per channel
z_data = scipy.stats.zscore(data, axis=0).mean(axis=1)

# plot the data
mne.viz.plot_topomap(z_data, pos=raw.info)

Hi @scott-huberty ,

Thanks for your reply.
The issue I am running into is that plot_topomap turns all the z-score values in the gradiometer channels positive.
I would like to have the actual z-scores from negative to positive with mean=0 on the colorbar.
Any hints?

Thanks,

Ana

Hi @anapesq - Looking at the documentation for plot_topomap, the ch_type parameter says:

For ‘grad’, the gradiometers are collected in pairs and the RMS for each pair is plotted.

Which probably explains why all the values in your topomap are positive. As for what you want to do, I’m not sure if there is a workaround to this (and I don’t know enough about MEG to know whether it is advisable to plot standalone gradiometer values as opposed to in pairs).

But maybe someone else here can provide more input.

Scott