

def _topomap_animation(evoked, ch_type='mag', times=None, frame_rate=None, butterfly=False, blit=True, show=True):
    "Make animation of evoked data as topomap timeseries. Animation can be\n    paused/resumed with left mouse button. Left and right arrow keys can be\n    used to move backward or forward in time.\n\n    Parameters\n    ----------\n    evoked : instance of Evoked\n        The evoked data.\n    ch_type : str | None\n        Channel type to plot. Accepted data types: 'mag', 'grad', 'eeg'.\n        If None, first available channel type from ('mag', 'grad', 'eeg') is\n        used. Defaults to None.\n    times : array of floats | None\n        The time points to plot. If None, 10 evenly spaced samples are\n        calculated over the evoked time series. Defaults to None.\n    frame_rate : int | None\n        Frame rate for the animation in Hz. If None, frame rate = sfreq / 10.\n        Defaults to None.\n    butterfly : bool\n        Whether to plot the data as butterfly plot under the topomap.\n        Defaults to False.\n    blit : bool\n        Whether to use blit to optimize drawing. In general, it is recommended\n        to use blit in combination with ``show=True``. If you intend to save\n        the animation it is better to disable blit. For MacOSX blit is always\n        disabled. Defaults to True.\n    show : bool\n        Whether to show the animation. Defaults to True.\n\n    Returns\n    -------\n    fig : instance of matplotlib figure\n        The figure.\n    anim : instance of matplotlib FuncAnimation\n        Animation of the topomap.\n\n    Notes\n    -----\n    .. versionadded:: 0.12.0\n    "
    from matplotlib import pyplot as plt, animation
    if (ch_type is None):
        ch_type = _picks_by_type(evoked.info)[0][0]
    if (ch_type not in ('mag', 'grad', 'eeg')):
        raise ValueError("Channel type not supported. Supported channel types include 'mag', 'grad' and 'eeg'.")
    if (times is None):
        times = np.linspace(evoked.times[0], evoked.times[(- 1)], 10)
    times = np.array(times)
    if (times.ndim != 1):
        raise ValueError(('times must be 1D, got %d dimensions' % times.ndim))
    if ((max(times) > evoked.times[(- 1)]) or (min(times) < evoked.times[0])):
        raise ValueError('All times must be inside the evoked time series.')
    frames = [np.abs((evoked.times - time)).argmin() for time in times]
    blit = (False if (plt.get_backend() == 'MacOSX') else True)
    (picks, pos, merge_grads, _, ch_type) = _prepare_topo_plot(evoked, ch_type=ch_type, layout=None)
    data = evoked.data[picks, :]
    data *= _handle_default('scalings')[ch_type]
    fig = plt.figure()
    offset = (0.0 if blit else 0.4)
    ax = plt.axes([(0.0 + (offset / 2.0)), (0.0 + (offset / 2.0)), (1.0 - offset), (1.0 - offset)], xlim=((- 1), 1), ylim=((- 1), 1))
    if butterfly:
        ax_line = plt.axes([0.2, 0.05, 0.6, 0.1], xlim=(evoked.times[0], evoked.times[(- 1)]))
    else:
        ax_line = None
    if isinstance(frames, int):
        frames = np.linspace(0, (len(evoked.times) - 1), frames).astype(int)
    ax_cbar = plt.axes([0.85, 0.1, 0.05, 0.8])
    ax_cbar.set_title(_handle_default('units')[ch_type], fontsize=10)
    params = {
        'data': data,
        'pos': pos,
        'all_times': evoked.times,
        'frame': 0,
        'frames': frames,
        'butterfly': butterfly,
        'blit': blit,
        'pause': False,
        'times': times,
    }
    init_func = partial(_init_anim, ax=ax, ax_cbar=ax_cbar, ax_line=ax_line, params=params, merge_grads=merge_grads)
    animate_func = partial(_animate, ax=ax, ax_line=ax_line, params=params)
    pause_func = partial(_pause_anim, params=params)
    fig.canvas.mpl_connect('button_press_event', pause_func)
    key_press_func = partial(_key_press, params=params)
    fig.canvas.mpl_connect('key_press_event', key_press_func)
    if (ax is None):
        frame_rate = (evoked.info['sfreq'] / 10.0)
    interval = (1000 / frame_rate)
    anim = animation.FuncAnimation(fig, animate_func, init_func=init_func, frames=len(frames), interval=interval, blit=blit)
    fig.mne_animation = anim
    if show:
        plt.show()
    if ('line' in params):
        params['line'].remove()
    return (fig, anim)

dataset/ETHPy150Open mne-tools/mne-python/mne/viz/topomap.py _topomap_animation/VarMisuse@645/1493 `frame_rate`->`ax`