Skip to content

Commit 039e712

Browse files
authored
FIX: Fix bug with raw scrolling (#8089) (#8212)
1 parent 4577b5f commit 039e712

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

mne/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def pytest_configure(config):
8888
ignore:.*tostring.*is deprecated.*:DeprecationWarning
8989
always:.*get_data.* is deprecated in favor of.*:DeprecationWarning
9090
ignore:.*Passing the dash.*:
91+
ignore:.*a deprecated alias.*:
9192
""" # noqa: E501
9293
for warning_line in warning_lines.split('\n'):
9394
warning_line = warning_line.strip()

mne/viz/raw.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import copy
1010
from functools import partial
11+
import warnings
1112

1213
import numpy as np
1314

@@ -649,7 +650,9 @@ def _prepare_mne_browse_raw(params, title, bgcolor, color, bad_color, inds,
649650

650651
figsize = _get_figsize_from_config()
651652
params['fig'] = figure_nobar(facecolor=bgcolor, figsize=figsize)
652-
params['fig'].canvas.set_window_title(title or "Raw")
653+
with warnings.catch_warnings(record=True):
654+
warnings.simplefilter('ignore')
655+
params['fig'].canvas.set_window_title(title or "Raw")
653656
# most of the axes setup is done in _prepare_mne_browse
654657
_prepare_mne_browse(params, xlabel='Time (s)')
655658
ax = params['ax']
@@ -719,7 +722,9 @@ def _prepare_mne_browse_raw(params, title, bgcolor, color, bad_color, inds,
719722

720723
params['lines'] = [ax.plot([np.nan], antialiased=True, linewidth=0.5)[0]
721724
for _ in range(n_ch)]
722-
ax.set_yticklabels(['X' * max([len(ch) for ch in info['ch_names']])])
725+
726+
ax.set_yticklabels(['X' * max([len(ch) for ch in info['ch_names']])] *
727+
len(params['offsets']))
723728
params['fig_annotation'] = None
724729
params['fig_help'] = None
725730
params['segment_line'] = None
@@ -742,7 +747,6 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
742747
offsets = params['offsets']
743748
params['bad_color'] = bad_color
744749
ax = params['ax']
745-
labels = ax.yaxis.get_ticklabels()
746750
# Scalebars
747751
for bar in params.get('scalebars', {}).values():
748752
ax.lines.remove(bar)
@@ -751,6 +755,7 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
751755
params['ax'].texts = []
752756
# do the plotting
753757
tick_list = list()
758+
tick_colors = list()
754759
for ii in range(n_channels):
755760
ch_ind = ii + ch_start
756761
# let's be generous here and allow users to pass
@@ -798,13 +803,11 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
798803
this_z = 2
799804
elif params['types'][ii] == 'grad':
800805
this_z = 3
801-
for label in labels:
802-
label.set_color('black')
803806
else:
804807
# set label color
805808
this_color = (bad_color if ch_name in info['bads'] else
806809
this_color)
807-
labels[ii].set_color(this_color)
810+
tick_colors.append(this_color)
808811
lines[ii].set_zorder(this_z)
809812
# add a scale bar
810813
if (params['show_scalebars'] and
@@ -904,6 +907,11 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
904907
params['ax'].set_yticks(params['offsets'][:len(tick_list)])
905908
params['ax'].set_yticklabels(tick_list, rotation=0)
906909
_set_ax_label_style(params['ax'], params)
910+
else:
911+
tick_colors = ['k'] * len(params['ax'].get_yticks())
912+
for tick_color, tick in zip(tick_colors,
913+
params['ax'].yaxis.get_ticklabels()):
914+
tick.set_color(tick_color)
907915
if 'fig_selection' not in params:
908916
params['vsel_patch'].set_y(params['ch_start'])
909917
params['fig'].canvas.draw()
@@ -1055,7 +1063,9 @@ def _setup_browser_selection(raw, kind, selector=True):
10551063
if not selector:
10561064
return order
10571065
fig_selection = figure_nobar(figsize=(2, 6), dpi=80)
1058-
fig_selection.canvas.set_window_title('Selection')
1066+
with warnings.catch_warnings(record=True):
1067+
warnings.simplefilter('ignore')
1068+
fig_selection.canvas.set_window_title('Selection')
10591069
rax = plt.subplot2grid((6, 1), (2, 0), rowspan=4, colspan=1)
10601070
topo_ax = plt.subplot2grid((6, 1), (0, 0), rowspan=2, colspan=1)
10611071
keys = np.concatenate([keys, ['Custom']])

mne/viz/tests/test_raw.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,15 @@ def test_scale_bar():
173173
plt.close('all')
174174

175175

176-
def test_plot_raw():
176+
def test_plot_raw_traces():
177177
"""Test plotting of raw data."""
178178
raw = _get_raw()
179179
raw.info['lowpass'] = 10. # allow heavy decim during plotting
180180
events = _get_events()
181181
plt.close('all') # ensure all are closed
182182
assert len(plt.get_fignums()) == 0
183-
fig = raw.plot(events=events, order=[1, 7, 3], group_by='original')
183+
fig = raw.plot(events=events, order=[1, 7, 5, 2, 3], n_channels=3,
184+
group_by='original')
184185
assert len(plt.get_fignums()) == 1
185186

186187
# make sure fig._mne_params is present
@@ -190,13 +191,21 @@ def test_plot_raw():
190191
x = fig.get_axes()[0].lines[1].get_xdata().mean()
191192
y = fig.get_axes()[0].lines[1].get_ydata().mean()
192193
data_ax = fig.axes[0]
194+
assert len(fig.axes) == 5
193195

194196
_fake_click(fig, data_ax, [x, y], xform='data') # mark a bad channel
195197
_fake_click(fig, data_ax, [x, y], xform='data') # unmark a bad channel
196198
_fake_click(fig, data_ax, [0.5, 0.999]) # click elsewhere in 1st axes
197199
_fake_click(fig, data_ax, [-0.1, 0.9]) # click on y-label
198-
_fake_click(fig, fig.get_axes()[1], [0.5, 0.5]) # change time
199-
_fake_click(fig, fig.get_axes()[2], [0.5, 0.5]) # change channels
200+
_fake_click(fig, fig.axes[1], [0.5, 0.5]) # change time
201+
labels = [label.get_text() for label in data_ax.get_yticklabels()]
202+
assert labels == [raw.ch_names[1], raw.ch_names[7], raw.ch_names[5]]
203+
_fake_click(fig, fig.axes[2], [0.5, 0.01]) # change channels to end
204+
labels = [label.get_text() for label in data_ax.get_yticklabels()]
205+
assert labels == [raw.ch_names[2], raw.ch_names[3]]
206+
_fake_click(fig, fig.axes[2], [0.5, 0.5]) # change channels to mid
207+
labels = [label.get_text() for label in data_ax.get_yticklabels()]
208+
assert labels == [raw.ch_names[7], raw.ch_names[5], raw.ch_names[2]]
200209
assert len(plt.get_fignums()) == 1
201210
# open SSP window
202211
_fake_click(fig, fig.get_axes()[-1], [0.5, 0.5])

mne/viz/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,9 @@ def _draw_proj_checkbox(event, params, draw_current_state=True):
506506
width = max([4., max([len(p['desc']) for p in projs]) / 6.0 + 0.5])
507507
height = (len(projs) + 1) / 6.0 + 1.5
508508
fig_proj = figure_nobar(figsize=(width, height))
509-
fig_proj.canvas.set_window_title('SSP projection vectors')
509+
with warnings.catch_warnings(record=True):
510+
warnings.simplefilter('ignore')
511+
fig_proj.canvas.set_window_title('SSP projection vectors')
510512
offset = (1. / 6. / height)
511513
params['fig_proj'] = fig_proj # necessary for proper toggling
512514
ax_temp = fig_proj.add_axes((0, offset, 1, 0.8 - offset), frameon=False)
@@ -1080,7 +1082,9 @@ def _setup_annotation_fig(params):
10801082

10811083
annotations_closed = partial(_annotations_closed, params=params)
10821084
fig.canvas.mpl_connect('close_event', annotations_closed)
1083-
fig.canvas.set_window_title('Annotations')
1085+
with warnings.catch_warnings(record=True):
1086+
warnings.simplefilter('ignore')
1087+
fig.canvas.set_window_title('Annotations')
10841088
fig.radio = RadioButtons(ax, labels, activecolor='#cccccc')
10851089
radius = 0.15
10861090
circles = fig.radio.circles
@@ -1265,7 +1269,9 @@ def _select_bads(event, params, bads):
12651269

12661270
def _show_help(col1, col2, width, height):
12671271
fig_help = figure_nobar(figsize=(width, height), dpi=80)
1268-
fig_help.canvas.set_window_title('Help')
1272+
with warnings.catch_warnings(record=True):
1273+
warnings.simplefilter('ignore')
1274+
fig_help.canvas.set_window_title('Help')
12691275

12701276
ax = fig_help.add_subplot(111)
12711277
celltext = [[c1, c2] for c1, c2 in zip(col1.strip().split("\n"),

0 commit comments

Comments
 (0)