From 553b32587dc7b8a8b02a234b125bf84737a09fd6 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 15 Sep 2023 11:07:57 -0400 Subject: [PATCH] BUG: Fix bug with clip box setting --- examples/io/elekta_epochs.py | 5 ++--- mne/viz/topo.py | 18 +++++++++++++----- tutorials/preprocessing/70_fnirs_processing.py | 1 - .../time-freq/20_sensors_time_frequency.py | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/io/elekta_epochs.py b/examples/io/elekta_epochs.py index 125a1e2c028..f632b0fbae3 100644 --- a/examples/io/elekta_epochs.py +++ b/examples/io/elekta_epochs.py @@ -5,9 +5,8 @@ Getting averaging info from .fif files ====================================== -Parse averaging information defined in Elekta Vectorview/TRIUX DACQ (data -acquisition). Extract and average epochs accordingly. Modify some -averaging parameters and get epochs. +Parse averaging information defined in Elekta Vectorview/TRIUX DACQ (data acquisition). +Extract and average epochs accordingly. Modify some averaging parameters and get epochs. """ # Author: Jussi Nurminen (jnu@iki.fi) # diff --git a/mne/viz/topo.py b/mne/viz/topo.py index d0b93dcc124..a01ee72a0c2 100644 --- a/mne/viz/topo.py +++ b/mne/viz/topo.py @@ -496,8 +496,6 @@ def _imshow_tfr_unified( data_lines.append( ax.imshow( tfr[ch_idx], - clip_on=True, - clip_box=tuple(bn.pos), extent=extent, aspect="auto", origin="lower", @@ -506,6 +504,7 @@ def _imshow_tfr_unified( cmap=cmap, ) ) + data_lines[-1].set_clip_box(_pos_to_bbox(bn.pos, ax)) def _plot_timeseries( @@ -664,7 +663,6 @@ def _plot_timeseries_unified( pos = bn.pos data_lines = bn.data_lines ax = bn.ax - # XXX These calls could probably be made faster by using collections for data_, color_, times_ in zip(data, color, times): data_lines.append( ax.plot( @@ -672,10 +670,10 @@ def _plot_timeseries_unified( bn.y_t + bn.y_s * data_[ch_idx], linewidth=0.5, color=color_, - clip_on=True, - clip_box=tuple(pos), )[0] ) + # Needs to be done afterward for some reason (probable matlotlib bug) + data_lines[-1].set_clip_box(_pos_to_bbox(pos, ax)) if vline: vline = np.array(vline) * bn.x_s + bn.x_t ax.vlines( @@ -1300,3 +1298,13 @@ def plot_topo_image_epochs( add_background_image(fig, fig_background) plt_show(show) return fig + + +def _pos_to_bbox(pos, ax): + """Convert layout position to bbox.""" + import matplotlib.transforms as mtransforms + + return mtransforms.TransformedBbox( + mtransforms.Bbox.from_bounds(*pos), + ax.transAxes, + ) diff --git a/tutorials/preprocessing/70_fnirs_processing.py b/tutorials/preprocessing/70_fnirs_processing.py index e8c11f74673..1dd30c628ab 100644 --- a/tutorials/preprocessing/70_fnirs_processing.py +++ b/tutorials/preprocessing/70_fnirs_processing.py @@ -12,7 +12,6 @@ Here we will work with the :ref:`fNIRS motor data `. """ - # %% import numpy as np diff --git a/tutorials/time-freq/20_sensors_time_frequency.py b/tutorials/time-freq/20_sensors_time_frequency.py index f707ee48d1a..776a230ecad 100644 --- a/tutorials/time-freq/20_sensors_time_frequency.py +++ b/tutorials/time-freq/20_sensors_time_frequency.py @@ -10,7 +10,7 @@ We will use this dataset: :ref:`somato-dataset`. It contains so-called event related synchronizations (ERS) / desynchronizations (ERD) in the beta band. -""" # noqa: E501 +""" # Authors: Alexandre Gramfort # Stefan Appelhoff # Richard Höchenberger