<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from functools import partial <EOL> from itertools import cycle <EOL> import numpy as np <EOL> from . . io . constants import Bunch <EOL> from . . io . pick import channel_type , pick_types <EOL> from . . fixes import normalize_colors <EOL> from . . utils import _clean_names , warn <EOL> from . . channels . layout import _merge_grad_data , _pair_grad_sensors , find_layout <EOL> from . . defaults import _handle_default <EOL> from . utils import ( _check_delayed_ssp , COLORS , _draw_proj_checkbox , <EOL> add_background_image , plt_show , _setup_vmin_vmax ) <EOL> def iter_topography ( info , layout = None , on_pick = None , fig = None , <EOL> fig_facecolor = '<STR_LIT:k>' , axis_facecolor = '<STR_LIT:k>' , <EOL> axis_spinecolor = '<STR_LIT:k>' , layout_scale = None ) : <EOL> """<STR_LIT>""" <EOL> return _iter_topography ( info , layout , on_pick , fig , fig_facecolor , <EOL> axis_facecolor , axis_spinecolor , layout_scale ) <EOL> def _iter_topography ( info , layout , on_pick , fig , fig_facecolor = '<STR_LIT:k>' , <EOL> axis_facecolor = '<STR_LIT:k>' , axis_spinecolor = '<STR_LIT:k>' , <EOL> layout_scale = None , unified = False , img = False ) : <EOL> """<STR_LIT>""" <EOL> from matplotlib import pyplot as plt , collections <EOL> if fig is None : <EOL> fig = plt . figure ( ) <EOL> fig . set_facecolor ( fig_facecolor ) <EOL> if layout is None : <EOL> layout = find_layout ( info ) <EOL> if on_pick is not None : <EOL> callback = partial ( _plot_topo_onpick , show_func = on_pick ) <EOL> fig . canvas . mpl_connect ( '<STR_LIT>' , callback ) <EOL> pos = layout . pos . copy ( ) <EOL> if layout_scale : <EOL> pos [ : , : <NUM_LIT:2> ] *= layout_scale <EOL> ch_names = _clean_names ( info [ '<STR_LIT>' ] ) <EOL> iter_ch = [ ( x , y ) for x , y in enumerate ( layout . names ) if y in ch_names ] <EOL> if unified : <EOL> under_ax = plt . axes ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> under_ax . set ( xlim = [ <NUM_LIT:0> , <NUM_LIT:1> ] , ylim = [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> under_ax . axis ( '<STR_LIT>' ) <EOL> axs = list ( ) <EOL> for idx , name in iter_ch : <EOL> ch_idx = ch_names . index ( name ) <EOL> if not unified : <EOL> ax = plt . axes ( pos [ idx ] ) <EOL> ax . patch . set_facecolor ( axis_facecolor ) <EOL> plt . setp ( list ( ax . spines . values ( ) ) , color = axis_spinecolor ) <EOL> ax . set_xticklabels ( [ ] ) <EOL> ax . set_yticklabels ( [ ] ) <EOL> plt . setp ( ax . get_xticklines ( ) , visible = False ) <EOL> plt . setp ( ax . get_yticklines ( ) , visible = False ) <EOL> ax . _mne_ch_name = name <EOL> ax . _mne_ch_idx = ch_idx <EOL> ax . _mne_ax_face_color = axis_facecolor <EOL> yield ax , ch_idx <EOL> else : <EOL> ax = Bunch ( ax = under_ax , pos = pos [ idx ] , data_lines = list ( ) , <EOL> _mne_ch_name = name , _mne_ch_idx = ch_idx , <EOL> _mne_ax_face_color = axis_facecolor ) <EOL> axs . append ( ax ) <EOL> if unified : <EOL> under_ax . _mne_axs = axs <EOL> verts = np . transpose ( [ pos [ : , : <NUM_LIT:2> ] , <EOL> pos [ : , : <NUM_LIT:2> ] + pos [ : , <NUM_LIT:2> : ] * [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> pos [ : , : <NUM_LIT:2> ] + pos [ : , <NUM_LIT:2> : ] , <EOL> pos [ : , : <NUM_LIT:2> ] + pos [ : , <NUM_LIT:2> : ] * [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> ] ) <EOL> if not img : <EOL> under_ax . add_collection ( collections . PolyCollection ( <EOL> verts , facecolor = axis_facecolor , edgecolor = axis_spinecolor , <EOL> linewidth = <NUM_LIT:1.> ) ) <EOL> for ax in axs : <EOL> yield ax , ax . _mne_ch_idx <EOL> def _plot_topo ( info , times , show_func , click_func = None , layout = None , <EOL> vmin = None , vmax = None , ylim = None , colorbar = None , <EOL> border = '<STR_LIT:none>' , axis_facecolor = '<STR_LIT:k>' , fig_facecolor = '<STR_LIT:k>' , <EOL> cmap = '<STR_LIT>' , layout_scale = None , title = None , x_label = None , <EOL> y_label = None , font_color = '<STR_LIT:w>' , unified = False , img = False ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib . pyplot as plt <EOL> tmin , tmax = times [ [ <NUM_LIT:0> , - <NUM_LIT:1> ] ] <EOL> click_func = show_func if click_func is None else click_func <EOL> on_pick = partial ( click_func , tmin = tmin , tmax = tmax , vmin = vmin , <EOL> vmax = vmax , ylim = ylim , x_label = x_label , <EOL> y_label = y_label , colorbar = colorbar ) <EOL> fig = plt . figure ( ) <EOL> if colorbar : <EOL> norm = normalize_colors ( vmin = vmin , vmax = vmax ) <EOL> sm = plt . cm . ScalarMappable ( cmap = cmap , norm = norm ) <EOL> sm . set_array ( np . linspace ( vmin , vmax ) ) <EOL> ax = plt . axes ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , axisbg = fig_facecolor ) <EOL> cb = fig . colorbar ( sm , ax = ax ) <EOL> cb_yticks = plt . getp ( cb . ax . axes , '<STR_LIT>' ) <EOL> plt . setp ( cb_yticks , color = font_color ) <EOL> ax . axis ( '<STR_LIT>' ) <EOL> my_topo_plot = _iter_topography ( info , layout = layout , on_pick = on_pick , <EOL> fig = fig , layout_scale = layout_scale , <EOL> axis_spinecolor = border , <EOL> axis_facecolor = axis_facecolor , <EOL> fig_facecolor = fig_facecolor , <EOL> unified = unified , img = img ) <EOL> for ax , ch_idx in my_topo_plot : <EOL> if layout . kind == '<STR_LIT>' and ylim is not None : <EOL> this_type = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:1> } [ channel_type ( info , ch_idx ) ] <EOL> ylim_ = [ v [ this_type ] if _check_vlim ( v ) else v for v in ylim ] <EOL> else : <EOL> ylim_ = ylim <EOL> show_func ( ax , ch_idx , tmin = tmin , tmax = tmax , vmin = vmin , <EOL> vmax = vmax , ylim = ylim_ ) <EOL> if title is not None : <EOL> plt . figtext ( <NUM_LIT> , <NUM_LIT> , title , color = font_color , fontsize = <NUM_LIT> ) <EOL> return fig <EOL> def _plot_topo_onpick ( event , show_func ) : <EOL> """<STR_LIT>""" <EOL> orig_ax = event . inaxes <EOL> if event . inaxes is None or ( not hasattr ( orig_ax , '<STR_LIT>' ) and <EOL> not hasattr ( orig_ax , '<STR_LIT>' ) ) : <EOL> return <EOL> import matplotlib . pyplot as plt <EOL> try : <EOL> if hasattr ( orig_ax , '<STR_LIT>' ) : <EOL> x , y = event . xdata , event . ydata <EOL> for ax in orig_ax . _mne_axs : <EOL> if x >= ax . pos [ <NUM_LIT:0> ] and y >= ax . pos [ <NUM_LIT:1> ] and x <= ax . pos [ <NUM_LIT:0> ] + ax . pos [ <NUM_LIT:2> ] and y <= ax . pos [ <NUM_LIT:1> ] + ax . pos [ <NUM_LIT:3> ] : <EOL> orig_ax = ax <EOL> break <EOL> else : <EOL> return <EOL> ch_idx = orig_ax . _mne_ch_idx <EOL> face_color = orig_ax . _mne_ax_face_color <EOL> fig , ax = plt . subplots ( <NUM_LIT:1> ) <EOL> plt . title ( orig_ax . _mne_ch_name ) <EOL> ax . set_axis_bgcolor ( face_color ) <EOL> show_func ( plt , ch_idx ) <EOL> except Exception as err : <EOL> print ( err ) <EOL> raise <EOL> def _compute_scalings ( bn , xlim , ylim ) : <EOL> """<STR_LIT>""" <EOL> pos = bn . pos <EOL> bn . x_s = pos [ <NUM_LIT:2> ] / ( xlim [ <NUM_LIT:1> ] - xlim [ <NUM_LIT:0> ] ) <EOL> bn . x_t = pos [ <NUM_LIT:0> ] - bn . x_s * xlim [ <NUM_LIT:0> ] <EOL> bn . y_s = pos [ <NUM_LIT:3> ] / ( ylim [ <NUM_LIT:1> ] - ylim [ <NUM_LIT:0> ] ) <EOL> bn . y_t = pos [ <NUM_LIT:1> ] - bn . y_s * ylim [ <NUM_LIT:0> ] <EOL> def _check_vlim ( vlim ) : <EOL> """<STR_LIT>""" <EOL> return not np . isscalar ( vlim ) and vlim is not None <EOL> def _imshow_tfr ( ax , ch_idx , tmin , tmax , vmin , vmax , onselect , ylim = None , <EOL> tfr = None , freq = None , vline = None , x_label = None , y_label = None , <EOL> colorbar = False , picker = True , cmap = '<STR_LIT>' , title = None , <EOL> hline = None ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib . widgets import RectangleSelector <EOL> extent = ( tmin , tmax , freq [ <NUM_LIT:0> ] , freq [ - <NUM_LIT:1> ] ) <EOL> img = ax . imshow ( tfr [ ch_idx ] , extent = extent , aspect = "<STR_LIT>" , origin = "<STR_LIT>" , <EOL> vmin = vmin , vmax = vmax , picker = picker , cmap = cmap ) <EOL> if isinstance ( ax , plt . Axes ) : <EOL> if x_label is not None : <EOL> ax . set_xlabel ( x_label ) <EOL> if y_label is not None : <EOL> ax . set_ylabel ( y_label ) <EOL> else : <EOL> if x_label is not None : <EOL> plt . xlabel ( x_label ) <EOL> if y_label is not None : <EOL> plt . ylabel ( y_label ) <EOL> if colorbar : <EOL> plt . colorbar ( mappable = img ) <EOL> if title : <EOL> plt . title ( title ) <EOL> if not isinstance ( ax , plt . Axes ) : <EOL> ax = plt . gca ( ) <EOL> ax . RS = RectangleSelector ( ax , onselect = onselect ) <EOL> def _imshow_tfr_unified ( bn , ch_idx , tmin , tmax , vmin , vmax , onselect , <EOL> ylim = None , tfr = None , freq = None , vline = None , <EOL> x_label = None , y_label = None , colorbar = False , <EOL> picker = True , cmap = '<STR_LIT>' , title = None , hline = None ) : <EOL> """<STR_LIT>""" <EOL> _compute_scalings ( bn , ( tmin , tmax ) , ( freq [ <NUM_LIT:0> ] , freq [ - <NUM_LIT:1> ] ) ) <EOL> ax = bn . ax <EOL> data_lines = bn . data_lines <EOL> extent = ( bn . x_t + bn . x_s * tmin , bn . x_t + bn . x_s * tmax , <EOL> bn . y_t + bn . y_s * freq [ <NUM_LIT:0> ] , bn . y_t + bn . y_s * freq [ - <NUM_LIT:1> ] ) <EOL> data_lines . append ( ax . imshow ( tfr [ ch_idx ] , clip_on = True , clip_box = bn . pos , <EOL> extent = extent , aspect = "<STR_LIT>" , origin = "<STR_LIT>" , <EOL> vmin = vmin , vmax = vmax , cmap = cmap ) ) <EOL> def _plot_timeseries ( ax , ch_idx , tmin , tmax , vmin , vmax , ylim , data , color , <EOL> times , vline = None , x_label = None , y_label = None , <EOL> colorbar = False , hline = None ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib . pyplot as plt <EOL> picker_flag = False <EOL> for data_ , color_ in zip ( data , color ) : <EOL> if not picker_flag : <EOL> ax . plot ( times , data_ [ ch_idx ] , color_ , picker = <NUM_LIT> ) <EOL> picker_flag = True <EOL> else : <EOL> ax . plot ( times , data_ [ ch_idx ] , color_ ) <EOL> if vline : <EOL> for x in vline : <EOL> plt . axvline ( x , color = '<STR_LIT:w>' , linewidth = <NUM_LIT:0.5> ) <EOL> if hline : <EOL> for y in hline : <EOL> plt . axhline ( y , color = '<STR_LIT:w>' , linewidth = <NUM_LIT:0.5> ) <EOL> if x_label is not None : <EOL> plt . xlabel ( x_label ) <EOL> if y_label is not None : <EOL> if isinstance ( y_label , list ) : <EOL> plt . ylabel ( y_label [ ch_idx ] ) <EOL> else : <EOL> plt . ylabel ( y_label ) <EOL> if colorbar : <EOL> plt . colorbar ( ) <EOL> def _plot_timeseries_unified ( bn , ch_idx , tmin , tmax , vmin , vmax , ylim , data , <EOL> color , times , vline = None , x_label = None , <EOL> y_label = None , colorbar = False , hline = None ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib . pyplot as plt <EOL> if not ( ylim and not any ( v is None for v in ylim ) ) : <EOL> ylim = np . array ( [ np . min ( data ) , np . max ( data ) ] ) <EOL> _compute_scalings ( bn , ( tmin , tmax ) , ylim ) <EOL> pos = bn . pos <EOL> data_lines = bn . data_lines <EOL> ax = bn . ax <EOL> for data_ , color_ in zip ( data , color ) : <EOL> data_lines . append ( ax . plot ( <EOL> bn . x_t + bn . x_s * times , bn . y_t + bn . y_s * data_ [ ch_idx ] , <EOL> color_ , clip_on = True , clip_box = pos ) [ <NUM_LIT:0> ] ) <EOL> if vline : <EOL> vline = np . array ( vline ) * bn . x_s + bn . x_t <EOL> ax . vlines ( vline , pos [ <NUM_LIT:1> ] , pos [ <NUM_LIT:1> ] + pos [ <NUM_LIT:3> ] , color = '<STR_LIT:w>' , linewidth = <NUM_LIT:0.5> ) <EOL> if hline : <EOL> hline = np . array ( hline ) * bn . y_s + bn . y_t <EOL> ax . hlines ( hline , pos [ <NUM_LIT:0> ] , pos [ <NUM_LIT:0> ] + pos [ <NUM_LIT:2> ] , color = '<STR_LIT:w>' , linewidth = <NUM_LIT:0.5> ) <EOL> if x_label is not None : <EOL> ax . text ( pos [ <NUM_LIT:0> ] + pos [ <NUM_LIT:2> ] / <NUM_LIT> , pos [ <NUM_LIT:1> ] , x_label , <EOL> horizontalalignment = '<STR_LIT>' , verticalalignment = '<STR_LIT>' ) <EOL> if y_label is not None : <EOL> y_label = y_label [ ch_idx ] if isinstance ( y_label , list ) else y_label <EOL> ax . text ( pos [ <NUM_LIT:0> ] , pos [ <NUM_LIT:1> ] + pos [ <NUM_LIT:3> ] / <NUM_LIT> , y_label , <EOL> horizontalignment = '<STR_LIT:right>' , verticalalignment = '<STR_LIT>' , <EOL> rotation = <NUM_LIT> ) <EOL> if colorbar : <EOL> plt . colorbar ( ) <EOL> def _erfimage_imshow ( ax , ch_idx , tmin , tmax , vmin , vmax , ylim = None , data = None , <EOL> epochs = None , sigma = None , order = None , scalings = None , <EOL> vline = None , x_label = None , y_label = None , colorbar = False , <EOL> cmap = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> from scipy import ndimage <EOL> import matplotlib . pyplot as plt <EOL> this_data = data [ : , ch_idx , : ] . copy ( ) <EOL> if callable ( order ) : <EOL> order = order ( epochs . times , this_data ) <EOL> if order is not None : <EOL> this_data = this_data [ order ] <EOL> if sigma > <NUM_LIT:0.> : <EOL> this_data = ndimage . gaussian_filter1d ( this_data , sigma = sigma , axis = <NUM_LIT:0> ) <EOL> ax . imshow ( this_data , extent = [ tmin , tmax , <NUM_LIT:0> , len ( data ) ] , aspect = '<STR_LIT>' , <EOL> origin = '<STR_LIT>' , vmin = vmin , vmax = vmax , picker = True , cmap = cmap , <EOL> interpolation = '<STR_LIT>' ) <EOL> ax = plt . gca ( ) <EOL> if x_label is not None : <EOL> ax . set_xlabel ( x_label ) <EOL> if y_label is not None : <EOL> ax . set_ylabel ( y_label ) <EOL> if colorbar : <EOL> plt . colorbar ( ) <EOL> def _erfimage_imshow_unified ( bn , ch_idx , tmin , tmax , vmin , vmax , ylim = None , <EOL> data = None , epochs = None , sigma = None , order = None , <EOL> scalings = None , vline = None , x_label = None , <EOL> y_label = None , colorbar = False , cmap = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> from scipy import ndimage <EOL> _compute_scalings ( bn , ( tmin , tmax ) , ( <NUM_LIT:0> , len ( epochs . events ) ) ) <EOL> ax = bn . ax <EOL> data_lines = bn . data_lines <EOL> extent = ( bn . x_t + bn . x_s * tmin , bn . x_t + bn . x_s * tmax , bn . y_t , <EOL> bn . y_t + bn . y_s * len ( epochs . events ) ) <EOL> this_data = data [ : , ch_idx , : ] . copy ( ) <EOL> if callable ( order ) : <EOL> order = order ( epochs . times , this_data ) <EOL> if order is not None : <EOL> this_data = this_data [ order ] <EOL> if sigma > <NUM_LIT:0.> : <EOL> this_data = ndimage . gaussian_filter1d ( this_data , sigma = sigma , axis = <NUM_LIT:0> ) <EOL> data_lines . append ( ax . imshow ( this_data , extent = extent , aspect = '<STR_LIT>' , <EOL> origin = '<STR_LIT>' , vmin = vmin , vmax = vmax , <EOL> picker = True , cmap = cmap , <EOL> interpolation = '<STR_LIT>' ) ) <EOL> def _plot_evoked_topo ( evoked , layout = None , layout_scale = <NUM_LIT> , color = None , <EOL> border = '<STR_LIT:none>' , ylim = None , scalings = None , title = None , <EOL> proj = False , vline = ( <NUM_LIT:0.> , ) , hline = ( <NUM_LIT:0.> , ) , fig_facecolor = '<STR_LIT:k>' , <EOL> fig_background = None , axis_facecolor = '<STR_LIT:k>' , font_color = '<STR_LIT:w>' , <EOL> merge_grads = False , show = True ) : <EOL> """<STR_LIT>""" <EOL> if not type ( evoked ) in ( tuple , list ) : <EOL> evoked = [ evoked ] <EOL> if type ( color ) in ( tuple , list ) : <EOL> if len ( color ) != len ( evoked ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif color is None : <EOL> colors = [ '<STR_LIT:w>' ] + COLORS <EOL> stop = ( slice ( len ( evoked ) ) if len ( evoked ) < len ( colors ) <EOL> else slice ( len ( colors ) ) ) <EOL> color = cycle ( colors [ stop ] ) <EOL> if len ( evoked ) > len ( colors ) : <EOL> warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> color = cycle ( [ color ] ) <EOL> times = evoked [ <NUM_LIT:0> ] . times <EOL> if not all ( ( e . times == times ) . all ( ) for e in evoked ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> evoked = [ e . copy ( ) for e in evoked ] <EOL> info = evoked [ <NUM_LIT:0> ] . info <EOL> ch_names = evoked [ <NUM_LIT:0> ] . ch_names <EOL> scalings = _handle_default ( '<STR_LIT>' , scalings ) <EOL> if not all ( e . ch_names == ch_names for e in evoked ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> ch_names = _clean_names ( ch_names ) <EOL> if merge_grads : <EOL> picks = _pair_grad_sensors ( info , topomap_coords = False ) <EOL> chs = list ( ) <EOL> for pick in picks [ : : <NUM_LIT:2> ] : <EOL> ch = info [ '<STR_LIT>' ] [ pick ] <EOL> ch [ '<STR_LIT>' ] = ch [ '<STR_LIT>' ] [ : - <NUM_LIT:1> ] + '<STR_LIT:X>' <EOL> chs . append ( ch ) <EOL> info [ '<STR_LIT>' ] = chs <EOL> info [ '<STR_LIT>' ] = list ( ) <EOL> info . _update_redundant ( ) <EOL> info . _check_consistency ( ) <EOL> new_picks = list ( ) <EOL> for e in evoked : <EOL> data = _merge_grad_data ( e . data [ picks ] ) * scalings [ '<STR_LIT>' ] <EOL> e . data = data <EOL> new_picks . append ( range ( len ( data ) ) ) <EOL> picks = new_picks <EOL> types_used = [ '<STR_LIT>' ] <EOL> y_label = '<STR_LIT>' % _handle_default ( '<STR_LIT>' ) [ '<STR_LIT>' ] <EOL> if layout is None : <EOL> layout = find_layout ( info ) <EOL> if not merge_grads : <EOL> chs_in_layout = set ( layout . names ) & set ( ch_names ) <EOL> types_used = set ( channel_type ( info , ch_names . index ( ch ) ) <EOL> for ch in chs_in_layout ) <EOL> types_used = set . difference ( types_used , set ( '<STR_LIT>' ) ) <EOL> meg_types = set ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> is_meg = len ( set . intersection ( types_used , meg_types ) ) > <NUM_LIT:0> <EOL> if is_meg : <EOL> types_used = list ( types_used ) [ : : - <NUM_LIT:1> ] <EOL> picks = [ pick_types ( info , meg = kk , ref_meg = False , exclude = [ ] ) <EOL> for kk in types_used ] <EOL> else : <EOL> types_used_kwargs = dict ( ( t , True ) for t in types_used ) <EOL> picks = [ pick_types ( info , meg = False , exclude = [ ] , <EOL> ** types_used_kwargs ) ] <EOL> assert isinstance ( picks , list ) and len ( types_used ) == len ( picks ) <EOL> for e in evoked : <EOL> for pick , ch_type in zip ( picks , types_used ) : <EOL> e . data [ pick ] = e . data [ pick ] * scalings [ ch_type ] <EOL> if proj is True and all ( e . proj is not True for e in evoked ) : <EOL> evoked = [ e . apply_proj ( ) for e in evoked ] <EOL> elif proj == '<STR_LIT>' : <EOL> for e in evoked : <EOL> _check_delayed_ssp ( e ) <EOL> y_label = [ '<STR_LIT>' % _handle_default ( '<STR_LIT>' ) [ channel_type ( <EOL> info , ch_idx ) ] for ch_idx in range ( len ( chs_in_layout ) ) ] <EOL> if ylim is None : <EOL> def set_ylim ( x ) : <EOL> return np . abs ( x ) . max ( ) <EOL> ylim_ = [ set_ylim ( [ e . data [ t ] for e in evoked ] ) for t in picks ] <EOL> ymax = np . array ( ylim_ ) <EOL> ylim_ = ( - ymax , ymax ) <EOL> elif isinstance ( ylim , dict ) : <EOL> ylim_ = _handle_default ( '<STR_LIT>' , ylim ) <EOL> ylim_ = [ ylim_ [ kk ] for kk in types_used ] <EOL> if len ( ylim_ ) == <NUM_LIT:1> : <EOL> ylim_ = ylim_ [ <NUM_LIT:0> ] <EOL> else : <EOL> ylim_ = zip ( * [ np . array ( yl ) for yl in ylim_ ] ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> data = [ e . data for e in evoked ] <EOL> show_func = partial ( _plot_timeseries_unified , data = data , <EOL> color = color , times = times , vline = vline , hline = hline ) <EOL> click_func = partial ( _plot_timeseries , data = data , <EOL> color = color , times = times , vline = vline , hline = hline ) <EOL> fig = _plot_topo ( info = info , times = times , show_func = show_func , <EOL> click_func = click_func , layout = layout , <EOL> colorbar = False , ylim = ylim_ , cmap = None , <EOL> layout_scale = layout_scale , border = border , <EOL> fig_facecolor = fig_facecolor , font_color = font_color , <EOL> axis_facecolor = axis_facecolor , title = title , <EOL> x_label = '<STR_LIT>' , y_label = y_label , unified = True ) <EOL> if fig_background is not None : <EOL> add_background_image ( fig , fig_background ) <EOL> if proj == '<STR_LIT>' : <EOL> for e in evoked : <EOL> _check_delayed_ssp ( e ) <EOL> params = dict ( evokeds = evoked , times = times , <EOL> plot_update_proj_callback = _plot_update_evoked_topo_proj , <EOL> projs = evoked [ <NUM_LIT:0> ] . info [ '<STR_LIT>' ] , fig = fig ) <EOL> _draw_proj_checkbox ( None , params ) <EOL> plt_show ( show ) <EOL> return fig <EOL> def _plot_update_evoked_topo_proj ( params , bools ) : <EOL> """<STR_LIT>""" <EOL> evokeds = [ e . copy ( ) for e in params [ '<STR_LIT>' ] ] <EOL> fig = params [ '<STR_LIT>' ] <EOL> projs = [ proj for proj , b in zip ( params [ '<STR_LIT>' ] , bools ) if b ] <EOL> params [ '<STR_LIT>' ] = bools <EOL> for e in evokeds : <EOL> e . add_proj ( projs , remove_existing = True ) <EOL> e . apply_proj ( ) <EOL> for ax in fig . axes [ <NUM_LIT:0> ] . _mne_axs : <EOL> for line , evoked in zip ( ax . data_lines , evokeds ) : <EOL> line . set_ydata ( ax . y_t + ax . y_s * evoked . data [ ax . _mne_ch_idx ] ) <EOL> fig . canvas . draw ( ) <EOL> def plot_topo_image_epochs ( epochs , layout = None , sigma = <NUM_LIT:0.> , vmin = None , <EOL> vmax = None , colorbar = True , order = None , cmap = '<STR_LIT>' , <EOL> layout_scale = <NUM_LIT> , title = None , scalings = None , <EOL> border = '<STR_LIT:none>' , fig_facecolor = '<STR_LIT:k>' , font_color = '<STR_LIT:w>' , <EOL> show = True ) : <EOL> """<STR_LIT>""" <EOL> scalings = _handle_default ( '<STR_LIT>' , scalings ) <EOL> data = epochs . get_data ( ) <EOL> scale_coeffs = list ( ) <EOL> for idx in range ( epochs . info [ '<STR_LIT>' ] ) : <EOL> ch_type = channel_type ( epochs . info , idx ) <EOL> scale_coeffs . append ( scalings . get ( ch_type , <NUM_LIT:1> ) ) <EOL> for epoch_data in data : <EOL> epoch_data *= np . asarray ( scale_coeffs ) [ : , np . newaxis ] <EOL> vmin , vmax = _setup_vmin_vmax ( data , vmin , vmax ) <EOL> if layout is None : <EOL> layout = find_layout ( epochs . info ) <EOL> show_func = partial ( _erfimage_imshow_unified , scalings = scalings , <EOL> order = order , data = data , epochs = epochs , sigma = sigma , <EOL> cmap = cmap ) <EOL> erf_imshow = partial ( _erfimage_imshow , scalings = scalings , order = order , <EOL> data = data , epochs = epochs , sigma = sigma , cmap = cmap ) <EOL> fig = _plot_topo ( info = epochs . info , times = epochs . times , <EOL> click_func = erf_imshow , show_func = show_func , layout = layout , <EOL> colorbar = colorbar , vmin = vmin , vmax = vmax , cmap = cmap , <EOL> layout_scale = layout_scale , title = title , <EOL> fig_facecolor = fig_facecolor , font_color = font_color , <EOL> border = border , x_label = '<STR_LIT>' , y_label = '<STR_LIT>' , <EOL> unified = True , img = True ) <EOL> plt_show ( show ) <EOL> return fig </s>
