Waveform Averaging Analysis NIRS Tutorial

Hi, here are my setup details :
Platform: Windows-10-10
Python: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
mne: 1.0.2
matplotlib: 3.5.1 {backend=module://matplotlib_inline.backend_inline}
mne_nirs: 0.4.0

I’m trying to reproduce the following image from the MNE-NIRS tutorial : Waveform Averaging Analysis — MNE-NIRS 0.4.0 documentation . But I can’t obtain both blue and red signals on the same plot. They are plotting fine independently but I can’t manage to combine them.

Can you please share what you actually get?

I only get the ouput of the left hand motion block average.
image

lots of things might be going wrong here. The first thing I would try is adding this:

import matplotlib.pyplot as plt
plt.ion()

to the beginning of the script. If that fixes it, then the problem was that the first call to plot_evoked_topo was “blocking” execution of the remainder of the script, which will then run only after you’ve closed the first plot window. using plt.ion() prevents figures from blocking execution.

Adding plt.ion() at the begining did not change anything.
I don’t know if I was clear enough yesterday, I’m just running the tutorial right now (Waveform Averaging Analysis — MNE-NIRS 0.4.0 documentation) and my output for the last figure is different from what is presented on the tutorial.

1 Like

I can reproduce the problem, and for me adding plt.ion() just before running the last code block works to fix it (I’m doing the tutorial in an interactive iPython terminal session). Another thing that also works is to add show=False to each of the two calls to mne.viz.plot_evoked_topo() in that last code block, and the add a line to the end fig.show(). So like this:

fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(6, 4))
mne.viz.plot_evoked_topo(epochs['Left'].average(picks='hbo'), color='b',
                         axes=axes, legend=False, show=False)  # <--- ADD show=False
mne.viz.plot_evoked_topo(epochs['Right'].average(picks='hbo'), color='r',
                         axes=axes, legend=False, show=False)  # <--- ADD show=False

# Tidy the legend:
leg_lines = [line for line in axes.lines if line.get_c() == 'b'][:1]
leg_lines.append([line for line in axes.lines if line.get_c() == 'r'][0])
fig.legend(leg_lines, ['Left', 'Right'], loc='lower right')
fig.show()  # <----- *** ADD THIS ***

It works, Thank you !