#NEWLINE# def _prepare_butterfly( params ) : #NEWLINE# #INDENT# 'Helper function for setting up butterfly plot.' #NEWLINE# from matplotlib.collections import LineCollection #NEWLINE# butterfly = ( not params [ 'butterfly' ] ) #NEWLINE# if butterfly : #NEWLINE# #INDENT# types = ( set ( [ 'grad' , 'mag' , 'eeg' , 'eog' , 'ecg' ] ) & set ( params [ 'types' ] ) ) #NEWLINE# if ( len ( types ) < 1 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# params [ 'ax_vscroll' ] . set_visible ( False ) #NEWLINE# ax = params [ 'ax' ] #NEWLINE# labels = ax . yaxis . get_ticklabels ( ) #NEWLINE# for label in labels : #NEWLINE# #INDENT# label . set_visible ( True ) #NEWLINE# #UNINDENT# ylim = ( ( 5.0 * len ( types ) ) , 0.0 ) #NEWLINE# ax . set_ylim ( ylim ) #NEWLINE# offset = ( ylim [ 0 ] / ( 4.0 * len ( types ) ) ) #NEWLINE# ticks = np . arange ( 0 , ylim [ 0 ] , offset ) #NEWLINE# ticks = [ ( ticks [ x ] if ( x < len ( ticks ) ) else 0 ) for x in range ( 20 ) ] #NEWLINE# ax . set_yticks ( ticks ) #NEWLINE# used_types = 0 #NEWLINE# params [ 'offsets' ] = [ ticks [ 2 ] ] #NEWLINE# if ( 'grad' in types ) : #NEWLINE# #INDENT# pos = ( 0 , ( 1 - ( ticks [ 2 ] / ylim [ 0 ] ) ) ) #NEWLINE# params [ 'ax2' ] . annotate ( 'Grad (fT/cm)' , xy = pos , xytext = ( ( - 70 ) , 0 ) , ha = 'left' , size = 12 , va = 'center' , xycoords = 'axes fraction' , rotation = 90 , textcoords = 'offset points' ) #NEWLINE# used_types += 1 #NEWLINE# #UNINDENT# params [ 'offsets' ] . append ( ticks [ ( 2 + ( used_types * 4 ) ) ] ) #NEWLINE# if ( 'mag' in types ) : #NEWLINE# #INDENT# pos = ( 0 , ( 1 - ( ticks [ ( 2 + ( used_types * 4 ) ) ] / ylim [ 0 ] ) ) ) #NEWLINE# params [ 'ax2' ] . annotate ( 'Mag (fT)' , xy = pos , xytext = ( ( - 70 ) , 0 ) , ha = 'left' , size = 12 , va = 'center' , xycoords = 'axes fraction' , rotation = 90 , textcoords = 'offset points' ) #NEWLINE# used_types += 1 #NEWLINE# #UNINDENT# params [ 'offsets' ] . append ( ticks [ ( 2 + ( used_types * 4 ) ) ] ) #NEWLINE# if ( 'eeg' in types ) : #NEWLINE# #INDENT# pos = ( 0 , ( 1 - ( ticks [ ( 2 + ( used_types * 4 ) ) ] / ylim [ 0 ] ) ) ) #NEWLINE# params [ 'ax2' ] . annotate ( 'EEG (uV)' , xy = pos , xytext = ( ( - 70 ) , 0 ) , ha = 'left' , size = 12 , va = 'center' , xycoords = 'axes fraction' , rotation = 90 , textcoords = 'offset points' ) #NEWLINE# used_types += 1 #NEWLINE# #UNINDENT# params [ 'offsets' ] . append ( ticks [ ( 2 + ( used_types * 4 ) ) ] ) #NEWLINE# if ( 'eog' in types ) : #NEWLINE# #INDENT# pos = ( 0 , ( 1 - ( ticks [ ( 2 + ( used_types * 4 ) ) ] / ylim [ 0 ] ) ) ) #NEWLINE# params [ 'ax2' ] . annotate ( 'EOG (uV)' , xy = pos , xytext = ( ( - 70 ) , 0 ) , ha = 'left' , size = 12 , va = 'center' , xycoords = 'axes fraction' , rotation = 90 , textcoords = 'offset points' ) #NEWLINE# used_types += 1 #NEWLINE# #UNINDENT# params [ 'offsets' ] . append ( ticks [ ( 2 + ( used_types * 4 ) ) ] ) #NEWLINE# if ( 'ecg' in types ) : #NEWLINE# #INDENT# pos = ( 0 , ( 1 - ( ticks [ ( 2 + ( used_types * 4 ) ) ] / ylim [ 0 ] ) ) ) #NEWLINE# params [ 'ax2' ] . annotate ( 'ECG (uV)' , xy = pos , xytext = ( ( - 70 ) , 0 ) , ha = 'left' , size = 12 , va = 'center' , xycoords = 'axes fraction' , rotation = 90 , textcoords = 'offset points' ) #NEWLINE# used_types += 1 #NEWLINE# #UNINDENT# while ( len ( params [ 'lines' ] ) < len ( params [ 'picks' ] ) ) : #NEWLINE# #INDENT# lc = LineCollection ( list ( ) , antialiased = False , linewidths = 0.5 , zorder = 3 , picker = 3.0 ) #NEWLINE# ax . add_collection ( lc ) #NEWLINE# params [ 'lines' ] . append ( lc ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# labels = params [ 'ax' ] . yaxis . get_ticklabels ( ) #NEWLINE# for label in labels : #NEWLINE# #INDENT# label . set_visible ( params [ 'settings' ] [ 0 ] ) #NEWLINE# #UNINDENT# params [ 'ax_vscroll' ] . set_visible ( True ) #NEWLINE# while ( len ( params [ 'ax2' ] . texts ) > 0 ) : #NEWLINE# #INDENT# params [ 'ax2' ] . texts . pop ( ) #NEWLINE# #UNINDENT# n_channels = params [ 'n_channels' ] #NEWLINE# while ( len ( params [ 'lines' ] ) > n_channels ) : #NEWLINE# #INDENT# params [ 'ax' ] . collections . pop ( ) #NEWLINE# params [ 'lines' ] . pop ( ) #NEWLINE# #UNINDENT# ylim = ( 25.0 , 0.0 ) #NEWLINE# params [ 'ax' ] . set_ylim ( ylim ) #NEWLINE# offset = ( ylim [ 0 ] / n_channels ) #NEWLINE# params [ 'offsets' ] = ( ( np . arange ( n_channels ) * offset ) + ( offset / 2.0 ) ) #NEWLINE# params [ 'ax' ] . set_yticks ( params [ 'offsets' ] ) #NEWLINE# #UNINDENT# params [ 'butterfly' ] = butterfly