How to create interactive topoplot in mne?

I was trying to create interactive topoplot with slider in MNE and got stuck. Topomap (or topoplot) is drawn, but it doesnā€™t update when I move slider. Do you have any idea how to make it interactive?
EDIT: I want to scroll through time

data:

import mne
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.widgets import Slider, Button
%matplotlib widget
biosemi_montage = mne.channels.make_standard_montage('biosemi64')
n_channels = len(biosemi_montage.ch_names)
fake_info = mne.create_info(ch_names=biosemi_montage.ch_names, sfreq=250.,
                            ch_types='eeg')

rng = np.random.RandomState(0)
data = rng.normal(size=(n_channels, 100)) * 1e-6
fake_evoked = mne.EvokedArray(data, fake_info)
fake_evoked.set_montage(biosemi_montage)

code

fig, ax = plt.subplots()

init_time = 0
timing = [round(i, ndigits=3) for i in list(np.linspace(0, 1, 100))]
voltage = fake_evoked.data[:, timing.index(init_time)]

mne.viz.plot_topomap(voltage, fake_evoked.info, axes=ax,
                     image_interp='cubic', 
                     show=False)
ax.set_title('MNE', fontweight='bold')
axtime = fig.add_axes([0.25, 0.01, 0.65, 0.04])

time_slider = Slider(
    ax=axtime,
    label='Time [ms]',
    valmin=0,    valmax=1, valstep=100,
    valinit=init_time,
)
plt.text(0.9, 2, init_time)

# The function to be called anytime a slider's value changes
def update(val):
    #init_time = round(time_slider.val, ndigits=3)
    
    #mne.viz.plot_topomap(voltage[:, timing.index(init_time)], fake_evoked.info, axes=ax,
                    # show=False)
    #voltage = fake_evoked.data[:, timing.index(init_time)]
    #plt.text(0.9, 2, init_time)
    fig.canvas.draw_idle()


# register the update function with each slider
time_slider.on_changed(update)

plt.show()

I was inspired with this example, but the use a method line.set_ydata which definetely could be used for topoplot.

Hello @vladdez and welcome to the forum!

Can you try with the Qt-based backend instead?

%matplotlib qt

Best wishes,
Richard

I tried, it just appeared in a separate window, nothing changed.

Oh, only now I realize youā€™re adding your own custom slider. I thought you were talking about the interactive colorbar MNE creates automatically. My bad. ā€” Why donā€™t you just use the MNEā€˜s interactive colorbar?

Edit Oh so you want to scroll through time? I really should start reading properly :woman_facepalming:

Yes! I want to scroll through time and update topoplot.

I know this is not at all what you asked for, but are you aware of the interactive nature of our Evoked plots? You can select time periods and will get a popup window with the respective topomap (averaged across time).

have a look at evoked.animate_topomap(), see it in action here: Plotting topographic maps of evoked data ā€” MNE 1.4.dev0 documentation

Oh thatā€™s great! Thank you!
But strangely when I run the code there is no sliderā€¦

The slider only exists in our documentation, Iā€™m afraid :slight_smile:

Ah, unfortunately! That was the crucial part.