#NEWLINE# def plot_drop_log( drop_log , threshold = 0 , n_max_plot = 20 , subject = 'Unknown' , color = ( 0.9 , 0.9 , 0.9 ) , width = 0.8 , ignore = ( 'IGNORED' , ) , show = True ) : #NEWLINE# #INDENT# 'Show the channel stats based on a drop_log from Epochs\n\n    Parameters\n    ----------\n    drop_log : list of lists\n        Epoch drop log from Epochs.drop_log.\n    threshold : float\n        The percentage threshold to use to decide whether or not to\n        plot. Default is zero (always plot).\n    n_max_plot : int\n        Maximum number of channels to show stats for.\n    subject : str\n        The subject name to use in the title of the plot.\n    color : tuple | str\n        Color to use for the bars.\n    width : float\n        Width of the bars.\n    ignore : list\n        The drop reasons to ignore.\n    show : bool\n        Show figure if True.\n\n    Returns\n    -------\n    fig : Instance of matplotlib.figure.Figure\n        The figure.\n    ' #NEWLINE# import matplotlib.pyplot as plt #NEWLINE# from .. epochs import _drop_log_stats #NEWLINE# perc = _drop_log_stats ( drop_log , ignore ) #NEWLINE# scores = Counter ( [ ch for d in drop_log for ch in d if ( ch not in ignore ) ] ) #NEWLINE# ch_names = np . array ( list ( scores . keys ( ) ) ) #NEWLINE# fig = plt . figure ( ) #NEWLINE# if ( ( perc < threshold ) or ( len ( ch_names ) == 0 ) ) : #NEWLINE# #INDENT# plt . text ( 0 , 0 , 'No drops' ) #NEWLINE# return fig #NEWLINE# #UNINDENT# n_used = 0 #NEWLINE# for d in drop_log : #NEWLINE# #INDENT# if ( ( len ( d ) == 0 ) or any ( ( ( ch not in ignore ) for ch in d ) ) ) : #NEWLINE# #INDENT# n_used += 1 #NEWLINE# #UNINDENT# #UNINDENT# counts = ( ( 100 * np . array ( list ( scores . values ( ) ) , dtype = float ) ) / n_used ) #NEWLINE# n_plot = min ( n_max_plot , len ( ch_names ) ) #NEWLINE# order = np . flipud ( np . argsort ( counts ) ) #NEWLINE# plt . title ( ( '%s: %0.1f%%' % ( subject , perc ) ) ) #NEWLINE# x = np . arange ( n_plot ) #NEWLINE# plt . bar ( x , counts [ order [ : n_plot ] ] , color = color , width = width ) #NEWLINE# plt . xticks ( ( x + ( width / 2.0 ) ) , ch_names [ order [ : n_plot ] ] , rotation = 45 , horizontalalignment = 'right' ) #NEWLINE# plt . tick_params ( axis = 'x' , which = 'major' , labelsize = 10 ) #NEWLINE# plt . ylabel ( '% of epochs rejected' ) #NEWLINE# plt . xlim ( ( ( ( - width ) / 2.0 ) , ( ( n_plot - 1 ) + ( ( width * 3 ) / 2 ) ) ) ) #NEWLINE# plt . grid ( True , axis = 'y' ) #NEWLINE# tight_layout ( pad = 1 , fig = fig ) #NEWLINE# plt_show ( show ) #NEWLINE# return fig