how to solve the Value error "Some of the values {} are NaN."

Hi, I tried to visualize the parent waves and different waves using the mne.viz.plot_compare_evokeds function, but the results pop out an error line.

These are my code:

evokeds = {}
for cond in conditions: 
       evokeds[cond] = [epochs[subject][cond].copy().crop(tmin, tmax).average() for subject in subjects]

evokeds_diff = {}
for contr, cond in contrasts.items():
       evokeds_diff[contr] = [mne.combine_evoked([ c1, c2],
                                                  weights=[-1, 1])
                             for (c1, c2) in zip(evokeds[cond[0]],
                                                evokeds[cond[1]]) ]

ylim = {'eeg':[-15, 15]}
head_pos = 'upper center'
fig, axs = plt.subplots(3, 3, figsize=(18,14) , constrained_layout=True,
                        sharex=True, sharey=True)
ax = 0
for roi, chans in rois.items():
   if ax == 0:
     legend='lower center'
     show=False
   else:
     legend=False
     show=False
   mne.viz.plot_compare_evokeds ({c: evokeds[c] for c in conditions},
                                  picks=chans, combine='mean', ylim=ylim,
                                  colors=colors, linestyles=linestyles,
                                  show_sensors=”upper right”, legend=legend,
                                  ci=False, 
                                  axes=axs.reshape(-1)[ax], show=False
                                 );
    ax += 1
plt.show()

ylim = {'eeg':[-5, 5]}
head_pos = 'upper center'
fig, axs = plt.subplots(3, 3, figsize=(18,14) , constrained_layout=True,
                        sharex=True, sharey=True)
ax = 0
for roi, chans in rois.items():
   if ax == 0:
     legend='lower center'
     show=False
   else:
     legend=False
     show=False
   mne.viz.plot_compare_evokeds({c: evokeds_diff[c] for c in contrasts},
                                  picks=chans, combine='mean', ylim=ylim,
                                  show_sensors=”upper right”, legend=legend,
                                  ci=False, 
                                  axes=axs.reshape(-1)[ax], show=False
                                 );
   ax += 1
plt.show()

But the error hints that

Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\mne\viz\evoked.py", line 3135, in plot_compare_evokeds
    res = _get_data_and_ci(
          ^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\mne\viz\evoked.py", line 2513, in _get_data_and_ci
    _check_if_nan(data)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\mne\utils\check.py", line 651, in _check_if_nan
    raise ValueError("Some of the values {} are NaN.".format(msg))
ValueError: Some of the values  to be plotted are NaN.

Is there any wrong in my code or data?

I dropped some bad epochs, did that make the values NaN?

Thanks.

I have figured it out. I included the boundary event into the epochs.

1 Like