Skip to content

Commit

Permalink
[MRG] Correctly delete previous event texts (mne-tools#4692)
Browse files Browse the repository at this point in the history
* Correctly delete previous event texts

* Correctly delete previous event and annotation texts

* Add comments and whats_new

* Texts (events and annotations) are now correctly removed

* Insert newline in whats_new
  • Loading branch information
cbrnr authored and larsoner committed Nov 9, 2017
1 parent 5c5429a commit c772ede
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Bug

- Fix bug in threshold-free cluster enhancement parameter validation (:func:`mne.stats.permutation_cluster_1samp_test` and :func:`mne.stats.permutation_cluster_test`) by `Clemens Brunner`_

- Fix bug in :meth:`mne.io.Raw.plot` to correctly display event types when annotations are present by `Clemens Brunner`_

API
~~~

Expand Down
9 changes: 5 additions & 4 deletions mne/viz/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,17 +1012,18 @@ def _plot_raw_traces(params, color, bad_color, event_lines=None,
else:
line.set_xdata([])
line.set_ydata([])

params['ax'].texts = [] # delete event and annotation texts
# don't add event numbers for more than 50 visible events
if len(event_times) <= 50:
params['ax'].texts = []
for ev_time, ev_num in zip(event_times, event_nums):
if -1 in event_color or ev_num in event_color:
params['ax'].text(ev_time, -0.05, ev_num, fontsize=8,
ha='center')

if 'segments' in params:
while len(params['ax'].collections) > 0:
params['ax'].collections.pop(0)
params['ax'].texts.pop(0)
while len(params['ax'].collections) > 0: # delete previous annotations
params['ax'].collections.pop(-1)
segments = params['segments']
times = params['times']
ylim = params['ax'].get_ylim()
Expand Down
1 change: 0 additions & 1 deletion mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,6 @@ def _plot_annotations(raw, params):

while len(params['ax_hscroll'].collections) > 0:
params['ax_hscroll'].collections.pop()

segments = list()
# sort the segments by start time
ann_order = raw.annotations.onset.argsort(axis=0)
Expand Down

0 comments on commit c772ede

Please sign in to comment.