# Buggy code
def _imshow_tfr(
    ax,
    ch_idx,
    tmin,
    tmax,
    vmin,
    vmax,
    onselect,
    ylim=None,
    tfr=None,
    freq=None,
    vline=None,
    x_label=None,
    y_label=None,
    colorbar=False,
    picker=True,
    cmap="RdBu_r",
    title=None,
    hline=None,
):
    """Aux function to show time-freq map on topo"""
    import matplotlib.pyplot as plt
    from matplotlib.widgets import RectangleSelector

    extent = (tmin, tmax, freq[0], freq[-1])
    img = ax.imshow(
        tfr[ch_idx],
        extent=extent,
        aspect="auto",
        origin="lower",
        vmin=vmin,
        vmax=vmax,
        picker=picker,
        cmap=cmap,
    )
    if isinstance(ax, plt.Axes):
        if x_label is not None:
            ax.set_xlabel(x_label)
        if y_label is not None:
            ax.set_ylabel(y_label)
    else:
        if x_label is not None:
            plt.xlabel(x_label)
        if y_label is not None:
            plt.ylabel(y_label)
    if colorbar:
        plt.colorbar(mappable=img)
    if title:
        plt.title(title)
    if not isinstance(ax, plt.Axes):
        ax = plt.gca()
    ax.RS = RectangleSelector(ax, onselect=onselect)  # reference must be kept


# Traceback (ValueError)
n [15]: Traceback (most recent call last):
File "/tsi/doctorants/mainak/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 291, in mouseReleaseEvent
FigureCanvasBase.button_release_event(self, x, y, button)
File "/tsi/doctorants/mainak/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 1891, in button_release_event
self.callbacks.process(s, event)
File "/tsi/doctorants/mainak/anaconda/lib/python2.7/site-packages/matplotlib/cbook.py", line 533, in process
proxy(*args, **kwargs)
File "/tsi/doctorants/mainak/anaconda/lib/python2.7/site-packages/matplotlib/cbook.py", line 408, in __call__
return mtd(*args, **kwargs)
File "/tsi/doctorants/mainak/anaconda/lib/python2.7/site-packages/matplotlib/widgets.py", line 1250, in release
self.onselect(vmin, vmax)
File "/tsi/doctorants/mainak/mne-python/mne/viz/evoked.py", line 90, in _butterfly_onselect
layout=None)
File "/tsi/doctorants/mainak/mne-python/mne/viz/topomap.py", line 49, in _prepare_topo_plot
picks, pos = _pair_grad_sensors(info, layout)
File "/tsi/doctorants/mainak/mne-python/mne/channels/layout.py", line 689, in _pair_grad_sensors
raise ValueError("No 'grad' channel pairs found.")
ValueError: No 'grad' channel pairs found.

# Fixed code
def _imshow_tfr(
    ax,
    ch_idx,
    tmin,
    tmax,
    vmin,
    vmax,
    onselect,
    ylim=None,
    tfr=None,
    freq=None,
    vline=None,
    x_label=None,
    y_label=None,
    colorbar=False,
    picker=True,
    cmap=("RdBu_r", True),
    title=None,
    hline=None,
):
    """Aux function to show time-freq map on topo"""
    import matplotlib.pyplot as plt
    from matplotlib.widgets import RectangleSelector

    extent = (tmin, tmax, freq[0], freq[-1])
    cmap, interactive_cmap = cmap

    img = ax.imshow(
        tfr[ch_idx],
        extent=extent,
        aspect="auto",
        origin="lower",
        vmin=vmin,
        vmax=vmax,
        picker=picker,
        cmap=cmap,
    )
    if isinstance(ax, plt.Axes):
        if x_label is not None:
            ax.set_xlabel(x_label)
        if y_label is not None:
            ax.set_ylabel(y_label)
    else:
        if x_label is not None:
            plt.xlabel(x_label)
        if y_label is not None:
            plt.ylabel(y_label)
    if colorbar:
        if isinstance(colorbar, DraggableColorbar):
            cbar = colorbar.cbar  # this happens with multiaxes case
        else:
            cbar = plt.colorbar(mappable=img)
        if interactive_cmap:
            ax.CB = DraggableColorbar(cbar, img)
    if title:
        plt.title(title)
    if not isinstance(ax, plt.Axes):
        ax = plt.gca()
    ax.RS = RectangleSelector(ax, onselect=onselect)  # reference must be kept