# Buggy code
def _onselect(self, eclick, erelease, baseline, mode, layout):
    """Callback function called by rubber band selector in channel tfr."""
    import matplotlib.pyplot as plt
    from ..viz import plot_tfr_topomap

    if abs(eclick.x - erelease.x) < 0.1 or abs(eclick.y - erelease.y) < 0.1:
        return
    plt.ion()  # turn interactive mode on
    tmin = round(min(eclick.xdata, erelease.xdata) / 1000.0, 5)  # ms to s
    tmax = round(max(eclick.xdata, erelease.xdata) / 1000.0, 5)
    fmin = round(min(eclick.ydata, erelease.ydata), 5)  # Hz
    fmax = round(max(eclick.ydata, erelease.ydata), 5)
    tmin = min(self.times, key=lambda x: abs(x - tmin))  # find closest
    tmax = min(self.times, key=lambda x: abs(x - tmax))
    fmin = min(self.freqs, key=lambda x: abs(x - fmin))
    fmax = min(self.freqs, key=lambda x: abs(x - fmax))
    if tmin == tmax or fmin == fmax:
        logger.info(
            "The selected area is too small. Select a larger time-frequency window."
        )
        return

    types = list()
    if "eeg" in self:
        types.append("eeg")
    if "mag" in self:
        types.append("mag")
    if "grad" in self:
        types.append("grad")
    fig = figure_nobar()
    fig.suptitle(
        "{:.2f} s - {:.2f} s, {:.2f} Hz - {:.2f} Hz".format(tmin, tmax, fmin, fmax),
        y=0.04,
    )
    for idx, ch_type in enumerate(types):
        ax = plt.subplot(1, len(types), idx + 1)
        plot_tfr_topomap(
            self,
            ch_type=ch_type,
            tmin=tmin,
            tmax=tmax,
            fmin=fmin,
            fmax=fmax,
            layout=layout,
            baseline=baseline,
            mode=mode,
            cmap=None,
            title=ch_type,
            vmin=None,
            vmax=None,
            axes=ax,
        )


# 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 _onselect(self, eclick, erelease, baseline, mode, layout):
    """Callback function called by rubber band selector in channel tfr."""
    import matplotlib.pyplot as plt
    from ..viz import plot_tfr_topomap

    if abs(eclick.x - erelease.x) < 0.1 or abs(eclick.y - erelease.y) < 0.1:
        return
    plt.ion()  # turn interactive mode on
    tmin = round(min(eclick.xdata, erelease.xdata) / 1000.0, 5)  # ms to s
    tmax = round(max(eclick.xdata, erelease.xdata) / 1000.0, 5)
    fmin = round(min(eclick.ydata, erelease.ydata), 5)  # Hz
    fmax = round(max(eclick.ydata, erelease.ydata), 5)
    tmin = min(self.times, key=lambda x: abs(x - tmin))  # find closest
    tmax = min(self.times, key=lambda x: abs(x - tmax))
    fmin = min(self.freqs, key=lambda x: abs(x - fmin))
    fmax = min(self.freqs, key=lambda x: abs(x - fmax))
    if tmin == tmax or fmin == fmax:
        logger.info(
            "The selected area is too small. Select a larger time-frequency window."
        )
        return

    types = list()
    if "eeg" in self:
        types.append("eeg")
    if "mag" in self:
        types.append("mag")
    if "grad" in self:
        if (
            len(_pair_grad_sensors(self.info, topomap_coords=False, raise_error=False))
            >= 2
        ):
            types.append("grad")
        elif len(types) == 0:
            return  # Don't draw a figure for nothing.
    fig = figure_nobar()
    fig.suptitle(
        "{0:.2f} s - {1:.2f} s, {2:.2f} Hz - {3:.2f} Hz".format(tmin, tmax, fmin, fmax),
        y=0.04,
    )
    for idx, ch_type in enumerate(types):
        ax = plt.subplot(1, len(types), idx + 1)
        plot_tfr_topomap(
            self,
            ch_type=ch_type,
            tmin=tmin,
            tmax=tmax,
            fmin=fmin,
            fmax=fmax,
            layout=layout,
            baseline=baseline,
            mode=mode,
            cmap=None,
            title=ch_type,
            vmin=None,
            vmax=None,
            axes=ax,
        )