Skip to content

Commit

Permalink
FIX: Fix bug with raw scrolling (#8089) (#8212)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Sep 4, 2020
1 parent 4577b5f commit 039e712
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
1 change: 1 addition & 0 deletions mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def pytest_configure(config):
ignore:.*tostring.*is deprecated.*:DeprecationWarning
always:.*get_data.* is deprecated in favor of.*:DeprecationWarning
ignore:.*Passing the dash.*:
ignore:.*a deprecated alias.*:
""" # noqa: E501
for warning_line in warning_lines.split('\n'):
warning_line = warning_line.strip()
Expand Down
24 changes: 17 additions & 7 deletions mne/viz/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import copy
from functools import partial
import warnings

import numpy as np

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

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

params['lines'] = [ax.plot([np.nan], antialiased=True, linewidth=0.5)[0]
for _ in range(n_ch)]
ax.set_yticklabels(['X' * max([len(ch) for ch in info['ch_names']])])

ax.set_yticklabels(['X' * max([len(ch) for ch in info['ch_names']])] *
len(params['offsets']))
params['fig_annotation'] = None
params['fig_help'] = None
params['segment_line'] = None
Expand All @@ -742,7 +747,6 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
offsets = params['offsets']
params['bad_color'] = bad_color
ax = params['ax']
labels = ax.yaxis.get_ticklabels()
# Scalebars
for bar in params.get('scalebars', {}).values():
ax.lines.remove(bar)
Expand All @@ -751,6 +755,7 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
params['ax'].texts = []
# do the plotting
tick_list = list()
tick_colors = list()
for ii in range(n_channels):
ch_ind = ii + ch_start
# let's be generous here and allow users to pass
Expand Down Expand Up @@ -798,13 +803,11 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
this_z = 2
elif params['types'][ii] == 'grad':
this_z = 3
for label in labels:
label.set_color('black')
else:
# set label color
this_color = (bad_color if ch_name in info['bads'] else
this_color)
labels[ii].set_color(this_color)
tick_colors.append(this_color)
lines[ii].set_zorder(this_z)
# add a scale bar
if (params['show_scalebars'] and
Expand Down Expand Up @@ -904,6 +907,11 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
params['ax'].set_yticks(params['offsets'][:len(tick_list)])
params['ax'].set_yticklabels(tick_list, rotation=0)
_set_ax_label_style(params['ax'], params)
else:
tick_colors = ['k'] * len(params['ax'].get_yticks())
for tick_color, tick in zip(tick_colors,
params['ax'].yaxis.get_ticklabels()):
tick.set_color(tick_color)
if 'fig_selection' not in params:
params['vsel_patch'].set_y(params['ch_start'])
params['fig'].canvas.draw()
Expand Down Expand Up @@ -1055,7 +1063,9 @@ def _setup_browser_selection(raw, kind, selector=True):
if not selector:
return order
fig_selection = figure_nobar(figsize=(2, 6), dpi=80)
fig_selection.canvas.set_window_title('Selection')
with warnings.catch_warnings(record=True):
warnings.simplefilter('ignore')
fig_selection.canvas.set_window_title('Selection')
rax = plt.subplot2grid((6, 1), (2, 0), rowspan=4, colspan=1)
topo_ax = plt.subplot2grid((6, 1), (0, 0), rowspan=2, colspan=1)
keys = np.concatenate([keys, ['Custom']])
Expand Down
17 changes: 13 additions & 4 deletions mne/viz/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,15 @@ def test_scale_bar():
plt.close('all')


def test_plot_raw():
def test_plot_raw_traces():
"""Test plotting of raw data."""
raw = _get_raw()
raw.info['lowpass'] = 10. # allow heavy decim during plotting
events = _get_events()
plt.close('all') # ensure all are closed
assert len(plt.get_fignums()) == 0
fig = raw.plot(events=events, order=[1, 7, 3], group_by='original')
fig = raw.plot(events=events, order=[1, 7, 5, 2, 3], n_channels=3,
group_by='original')
assert len(plt.get_fignums()) == 1

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

_fake_click(fig, data_ax, [x, y], xform='data') # mark a bad channel
_fake_click(fig, data_ax, [x, y], xform='data') # unmark a bad channel
_fake_click(fig, data_ax, [0.5, 0.999]) # click elsewhere in 1st axes
_fake_click(fig, data_ax, [-0.1, 0.9]) # click on y-label
_fake_click(fig, fig.get_axes()[1], [0.5, 0.5]) # change time
_fake_click(fig, fig.get_axes()[2], [0.5, 0.5]) # change channels
_fake_click(fig, fig.axes[1], [0.5, 0.5]) # change time
labels = [label.get_text() for label in data_ax.get_yticklabels()]
assert labels == [raw.ch_names[1], raw.ch_names[7], raw.ch_names[5]]
_fake_click(fig, fig.axes[2], [0.5, 0.01]) # change channels to end
labels = [label.get_text() for label in data_ax.get_yticklabels()]
assert labels == [raw.ch_names[2], raw.ch_names[3]]
_fake_click(fig, fig.axes[2], [0.5, 0.5]) # change channels to mid
labels = [label.get_text() for label in data_ax.get_yticklabels()]
assert labels == [raw.ch_names[7], raw.ch_names[5], raw.ch_names[2]]
assert len(plt.get_fignums()) == 1
# open SSP window
_fake_click(fig, fig.get_axes()[-1], [0.5, 0.5])
Expand Down
12 changes: 9 additions & 3 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ def _draw_proj_checkbox(event, params, draw_current_state=True):
width = max([4., max([len(p['desc']) for p in projs]) / 6.0 + 0.5])
height = (len(projs) + 1) / 6.0 + 1.5
fig_proj = figure_nobar(figsize=(width, height))
fig_proj.canvas.set_window_title('SSP projection vectors')
with warnings.catch_warnings(record=True):
warnings.simplefilter('ignore')
fig_proj.canvas.set_window_title('SSP projection vectors')
offset = (1. / 6. / height)
params['fig_proj'] = fig_proj # necessary for proper toggling
ax_temp = fig_proj.add_axes((0, offset, 1, 0.8 - offset), frameon=False)
Expand Down Expand Up @@ -1080,7 +1082,9 @@ def _setup_annotation_fig(params):

annotations_closed = partial(_annotations_closed, params=params)
fig.canvas.mpl_connect('close_event', annotations_closed)
fig.canvas.set_window_title('Annotations')
with warnings.catch_warnings(record=True):
warnings.simplefilter('ignore')
fig.canvas.set_window_title('Annotations')
fig.radio = RadioButtons(ax, labels, activecolor='#cccccc')
radius = 0.15
circles = fig.radio.circles
Expand Down Expand Up @@ -1265,7 +1269,9 @@ def _select_bads(event, params, bads):

def _show_help(col1, col2, width, height):
fig_help = figure_nobar(figsize=(width, height), dpi=80)
fig_help.canvas.set_window_title('Help')
with warnings.catch_warnings(record=True):
warnings.simplefilter('ignore')
fig_help.canvas.set_window_title('Help')

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

0 comments on commit 039e712

Please sign in to comment.