Skip to content

Commit 7032648

Browse files
authored
Fix epochs.plot() scrollbar issue (#13654)
1 parent 8f75a7d commit 7032648

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

doc/changes/dev/13654.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug in :meth:`mne.Epochs.plot` where clicking on the scrollbar would not scroll to the last epoch, by `Clemens Brunner`_.

mne/viz/_mpl_figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ def _check_update_hscroll_clicked(self, event):
17541754
)
17551755
time = np.clip(time, self.mne.first_time, max_time)
17561756
if self.mne.is_epochs:
1757-
ix = np.searchsorted(self.mne.boundary_times[1:], time)
1757+
ix = np.searchsorted(self.mne.boundary_times[1:], time, side="right")
17581758
time = self.mne.boundary_times[ix]
17591759
if self.mne.t_start != time:
17601760
self.mne.t_start = time

mne/viz/tests/test_epochs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def test_plot_epochs_clicks(epochs, epochs_full, capsys, browser_backend):
136136
# test clicking scrollbars
137137
fig._fake_click((0.5, 0.5), ax=fig.mne.ax_vscroll)
138138
fig._fake_click((0.5, 0.5), ax=fig.mne.ax_hscroll)
139+
# clicking near right edge in hscroll should reach final epoch window
140+
fig._fake_click((0.99, 0.5), ax=fig.mne.ax_hscroll)
141+
max_t_start = fig.mne.n_times / fig.mne.info["sfreq"] - fig.mne.duration
142+
assert fig.mne.t_start == pytest.approx(max_t_start)
139143
# test moving bad epoch offscreen
140144
fig._fake_keypress("right") # move right
141145
x = fig.mne.traces[0].get_xdata()[-3]

0 commit comments

Comments
 (0)