Error in 'plot_topo' command when calculated tfr

Hi,
I am trying to use the ‘mne.time_frequency.tfr_multitaper’ command for EEG data time-frequency analysis. After running the grand average command, I want to view the topographic map. However, the following error occurred:

TypeError: ‘clipbox’ must be an instance of matplotlib.transforms.BboxBase or None, not a tuple

Thanks,
Jaye

File ~\AppData\Roaming\Python\Python311\site-packages\mne\time_frequency\tfr.py:2446, in AverageTFR.plot_topo(***failed resolving arguments***)
   2430 click_fun = partial(
   2431     _imshow_tfr,
   2432     tfr=data,
   (...)
   2436     onselect=onselect_callback,
   2437 )
   2438 imshow = partial(
   2439     _imshow_tfr_unified,
   2440     tfr=data,
   (...)
   2443     onselect=onselect_callback,
   2444 )
-> 2446 fig = _plot_topo(
   2447     info=info,
   2448     times=times,
   2449     show_func=imshow,
   2450     click_func=click_fun,
   2451     layout=layout,
   2452     colorbar=colorbar,
   2453     vmin=vmin,
   2454     vmax=vmax,
   2455     cmap=cmap,
   2456     layout_scale=layout_scale,
   2457     title=title,
   2458     border=border,
   2459     x_label="Time (s)",
   2460     y_label="Frequency (Hz)",
   2461     fig_facecolor=fig_facecolor,
   2462     font_color=font_color,
   2463     unified=True,
   2464     img=True,
   2465 )
   2467 add_background_image(fig, fig_background)
   2468 plt_show(show)

File ~\AppData\Roaming\Python\Python311\site-packages\mne\viz\topo.py:334, in _plot_topo(info, times, show_func, click_func, layout, vmin, vmax, ylim, colorbar, border, axis_facecolor, fig_facecolor, cmap, layout_scale, title, x_label, y_label, font_color, unified, img, axes)
    331     else:
    332         ylim_ = ylim
--> 334     show_func(ax, ch_idx, tmin=tmin, tmax=tmax, vmin=vmin, vmax=vmax, ylim=ylim_)
    336 if title is not None:
    337     plt.figtext(0.03, 0.95, title, color=font_color, fontsize=15, va="top")

File ~\AppData\Roaming\Python\Python311\site-packages\mne\viz\topo.py:496, in _imshow_tfr_unified(bn, ch_idx, tmin, tmax, vmin, vmax, onselect, ylim, tfr, freq, vline, x_label, y_label, colorbar, picker, cmap, title, hline)
    488 data_lines = bn.data_lines
    489 extent = (
    490     bn.x_t + bn.x_s * tmin,
    491     bn.x_t + bn.x_s * tmax,
    492     bn.y_t + bn.y_s * freq[0],
    493     bn.y_t + bn.y_s * freq[-1],
    494 )
    495 data_lines.append(
--> 496     ax.imshow(
    497         tfr[ch_idx],
    498         clip_on=True,
    499         clip_box=tuple(bn.pos),
    500         extent=extent,
    501         aspect="auto",
    502         origin="lower",
    503         vmin=vmin,
    504         vmax=vmax,
    505         cmap=cmap,
    506     )
    507 )

File ~\AppData\Roaming\Python\Python311\site-packages\matplotlib\__init__.py:1478, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
   1475 @functools.wraps(func)
   1476 def inner(ax, *args, data=None, **kwargs):
   1477     if data is None:
-> 1478         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1480     bound = new_sig.bind(ax, *args, **kwargs)
   1481     auto_label = (bound.arguments.get(label_namer)
   1482                   or bound.kwargs.get(label_namer))

File ~\AppData\Roaming\Python\Python311\site-packages\matplotlib\axes\_axes.py:5737, in Axes.imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, interpolation_stage, filternorm, filterrad, resample, url, **kwargs)
   5532 @_preprocess_data()
   5533 @_docstring.interpd
   5534 def imshow(self, X, cmap=None, norm=None, *, aspect=None,
   (...)
   5537            interpolation_stage=None, filternorm=True, filterrad=4.0,
   5538            resample=None, url=None, **kwargs):
   5539     """
   5540     Display data as an image, i.e., on a 2D regular raster.
   5541 
   (...)
   5735     (unassociated) alpha representation.
   5736     """
-> 5737     im = mimage.AxesImage(self, cmap=cmap, norm=norm,
   5738                           interpolation=interpolation, origin=origin,
   5739                           extent=extent, filternorm=filternorm,
   5740                           filterrad=filterrad, resample=resample,
   5741                           interpolation_stage=interpolation_stage,
   5742                           **kwargs)
   5744     if aspect is None and not (
   5745             im.is_transform_set()
   5746             and not im.get_transform().contains_branch(self.transData)):
   5747         aspect = mpl.rcParams['image.aspect']

File ~\AppData\Roaming\Python\Python311\site-packages\matplotlib\image.py:912, in AxesImage.__init__(self, ax, cmap, norm, interpolation, origin, extent, filternorm, filterrad, resample, interpolation_stage, **kwargs)
    896 def __init__(self, ax,
    897              *,
    898              cmap=None,
   (...)
    907              **kwargs
    908              ):
    910     self._extent = extent
--> 912     super().__init__(
    913         ax,
    914         cmap=cmap,
    915         norm=norm,
    916         interpolation=interpolation,
    917         origin=origin,
    918         filternorm=filternorm,
    919         filterrad=filterrad,
    920         resample=resample,
    921         interpolation_stage=interpolation_stage,
    922         **kwargs
    923     )

File ~\AppData\Roaming\Python\Python311\site-packages\matplotlib\image.py:275, in _ImageBase.__init__(self, ax, cmap, norm, interpolation, origin, filternorm, filterrad, resample, interpolation_stage, **kwargs)
    271 self.axes = ax
    273 self._imcache = None
--> 275 self._internal_update(kwargs)

File ~\AppData\Roaming\Python\Python311\site-packages\matplotlib\artist.py:1219, in Artist._internal_update(self, kwargs)
   1212 def _internal_update(self, kwargs):
   1213     """
   1214     Update artist properties without prenormalizing them, but generating
   1215     errors as if calling `set`.
   1216 
   1217     The lack of prenormalization is to maintain backcompatibility.
   1218     """
-> 1219     return self._update_props(
   1220         kwargs, "{cls.__name__}.set() got an unexpected keyword argument "
   1221         "{prop_name!r}")

File ~\AppData\Roaming\Python\Python311\site-packages\matplotlib\artist.py:1195, in Artist._update_props(self, props, errfmt)
   1192             if not callable(func):
   1193                 raise AttributeError(
   1194                     errfmt.format(cls=type(self), prop_name=k))
-> 1195             ret.append(func(v))
   1196 if ret:
   1197     self.pchanged()

File ~\AppData\Roaming\Python\Python311\site-packages\matplotlib\artist.py:766, in Artist.set_clip_box(self, clipbox)
    754 def set_clip_box(self, clipbox):
    755     """
    756     Set the artist's clip `.Bbox`.
    757 
   (...)
    764 
    765     """
--> 766     _api.check_isinstance((BboxBase, None), clipbox=clipbox)
    767     if clipbox != self.clipbox:
    768         self.clipbox = clipbox

File ~\AppData\Roaming\Python\Python311\site-packages\matplotlib\_api\__init__.py:91, in check_isinstance(types, **kwargs)
     89     names.remove("None")
     90     names.append("None")
---> 91 raise TypeError(
     92     "{!r} must be an instance of {}, not a {}".format(
     93         k,
     94         ", ".join(names[:-1]) + " or " + names[-1]
     95         if len(names) > 1 else names[0],
     96         type_name(type(v))))

TypeError: 'clipbox' must be an instance of matplotlib.transforms.BboxBase or None, not a tuple


What version of MNE are you using? I think this was a bug that has been fixed, but you’ll need to update to the development version of MNE, or wait for the next stable version to be released. See
this answer

1 Like

Hi,
I used MNE version 1.5.1 and followed the steps to install git+https://github.com/mne-tools/mne-python.git@maint/1.5, but the problem persists.

1 Like

Hi, the problem was solved after I used: !pip install --upgrade git+https://github.com/mne-tools/mne-python@main.

Thanks for the help.

3 Likes