<s> """<STR_LIT>""" <EOL> import itertools <EOL> import matplotlib <EOL> from matplotlib import pyplot as plt <EOL> from matplotlib import mlab <EOL> import numpy as np <EOL> from matplotlib . ticker import MaxNLocator <EOL> from mpl_toolkits . axes_grid1 import make_axes_locatable <EOL> from matplotlib import gridspec <EOL> import colormap_adjust <EOL> from scipy import stats <EOL> def ci_plot ( x , arr , conf = <NUM_LIT> , ax = None , line_kwargs = None , fill_kwargs = None ) : <EOL> """<STR_LIT>""" <EOL> if ax is None : <EOL> fig = plt . figure ( ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> line_kwargs = line_kwargs or { } <EOL> fill_kwargs = fill_kwargs or { } <EOL> m , lo , hi = ci ( arr , conf ) <EOL> ax . plot ( x , m , ** line_kwargs ) <EOL> ax . fill_between ( x , lo , hi , ** fill_kwargs ) <EOL> return ax <EOL> def imshow ( arr , x = None , ax = None , vmin = None , vmax = None , percentile = True , <EOL> strip = False , features = None , conf = <NUM_LIT> , sort_by = None , <EOL> line_kwargs = None , fill_kwargs = None , imshow_kwargs = None , figsize = ( <NUM_LIT:5> , <NUM_LIT:12> ) , <EOL> width_ratios = ( <NUM_LIT:4> , <NUM_LIT:1> ) , height_ratios = ( <NUM_LIT:4> , <NUM_LIT:1> ) , <EOL> subplot_params = dict ( wspace = <NUM_LIT:0.1> , hspace = <NUM_LIT:0.1> ) , <EOL> subset_by = None , subset_order = None , ) : <EOL> """<STR_LIT>""" <EOL> if ax is None : <EOL> fig = new_shell ( <EOL> figsize = figsize , <EOL> strip = strip , <EOL> subplot_params = subplot_params , <EOL> width_ratios = width_ratios , <EOL> height_ratios = height_ratios ) <EOL> if x is None : <EOL> x = np . arange ( arr . shape [ <NUM_LIT:1> ] + <NUM_LIT:1> ) <EOL> if percentile : <EOL> if vmin is None : <EOL> vmin = arr . min ( ) <EOL> else : <EOL> vmin = mlab . prctile ( arr . ravel ( ) , vmin ) <EOL> if vmax is None : <EOL> vmax = arr . max ( ) <EOL> else : <EOL> vmax = mlab . prctile ( arr . ravel ( ) , vmax ) <EOL> else : <EOL> if vmin is None : <EOL> vmin = arr . min ( ) <EOL> if vmax is None : <EOL> vmax = arr . max ( ) <EOL> cmap = colormap_adjust . smart_colormap ( vmin , vmax ) <EOL> _imshow_kwargs = dict ( origin = '<STR_LIT>' , cmap = cmap , vmin = vmin , vmax = vmax , <EOL> aspect = '<STR_LIT>' ) <EOL> if imshow_kwargs is not None : <EOL> _imshow_kwargs . update ( imshow_kwargs ) <EOL> if sort_by is None : <EOL> sort_by = np . arange ( arr . shape [ <NUM_LIT:0> ] ) <EOL> if ax is None : <EOL> array_ax = fig . array_axes <EOL> else : <EOL> array_ax = ax <EOL> if subset_by is None : <EOL> subset_by = np . zeros ( arr . shape [ <NUM_LIT:0> ] ) <EOL> if not isinstance ( subset_by , np . ndarray ) : <EOL> subset_by = np . array ( subset_by ) <EOL> if subset_order is None : <EOL> subset_order = sorted ( np . unique ( subset_by ) ) <EOL> inds = [ ] <EOL> for cls in subset_order : <EOL> subset_ind = np . nonzero ( subset_by == cls ) [ <NUM_LIT:0> ] <EOL> subset_sort_by = sort_by [ subset_ind ] <EOL> subset_argsort_by = np . argsort ( subset_sort_by ) <EOL> inds . append ( subset_ind [ subset_argsort_by ] ) <EOL> ind = np . concatenate ( inds ) <EOL> mappable = array_ax . imshow ( <EOL> arr [ ind , : ] , <EOL> extent = ( x . min ( ) , x . max ( ) , <NUM_LIT:0> , arr . shape [ <NUM_LIT:0> ] ) , <EOL> ** _imshow_kwargs <EOL> ) <EOL> if line_kwargs is None : <EOL> line_kwargs = { } <EOL> if fill_kwargs is None : <EOL> fill_kwargs = { } <EOL> if isinstance ( line_kwargs , dict ) : <EOL> line_kwargs = [ line_kwargs ] <EOL> if isinstance ( fill_kwargs , dict ) : <EOL> fill_kwargs = [ fill_kwargs ] <EOL> _line_kwargs = itertools . cycle ( line_kwargs ) <EOL> _fill_kwargs = itertools . cycle ( fill_kwargs ) <EOL> if ax is None : <EOL> plt . colorbar ( mappable , fig . cax ) <EOL> for subset_ind , label , _lkw , _fkw in zip ( inds , subset_order , _line_kwargs , _fill_kwargs ) : <EOL> ci_plot ( <EOL> x , <EOL> arr [ subset_ind ] , <EOL> ax = fig . line_axes , <EOL> line_kwargs = _lkw , <EOL> fill_kwargs = _fkw , <EOL> ) <EOL> return fig <EOL> else : <EOL> return ax . figure <EOL> def add_labels_to_subsets ( ax , subset_by , subset_order , text_kwargs = None , <EOL> add_hlines = True , hline_kwargs = None ) : <EOL> """<STR_LIT>""" <EOL> _text_kwargs = dict ( transform = ax . get_yaxis_transform ( ) ) <EOL> if text_kwargs : <EOL> _text_kwargs . update ( text_kwargs ) <EOL> _hline_kwargs = dict ( color = '<STR_LIT:k>' ) <EOL> if hline_kwargs : <EOL> _hline_kwargs . update ( hline_kwargs ) <EOL> pos = <NUM_LIT:0> <EOL> for label in subset_order : <EOL> ind = subset_by == label <EOL> last_pos = pos <EOL> pos += sum ( ind ) <EOL> if add_hlines : <EOL> ax . axhline ( pos , ** _hline_kwargs ) <EOL> ax . text ( <EOL> <NUM_LIT> , <EOL> last_pos + ( pos - last_pos ) / <NUM_LIT> , <EOL> label , <EOL> ** _text_kwargs ) <EOL> def calculate_limits ( array_dict , method = '<STR_LIT>' , percentiles = None , limit = ( ) ) : <EOL> """<STR_LIT>""" <EOL> if percentiles is not None : <EOL> for percentile in percentiles : <EOL> if not <NUM_LIT:0> <= percentile <= <NUM_LIT:100> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if method == '<STR_LIT>' : <EOL> all_arrays = np . concatenate ( <EOL> [ i . ravel ( ) for i in array_dict . itervalues ( ) ] <EOL> ) <EOL> if percentiles : <EOL> vmin = mlab . prctile ( <EOL> all_arrays , percentiles [ <NUM_LIT:0> ] ) <EOL> vmax = mlab . prctile ( <EOL> all_arrays , percentiles [ <NUM_LIT:1> ] ) <EOL> else : <EOL> vmin = all_arrays . min ( ) <EOL> vmax = all_arrays . max ( ) <EOL> d = dict ( [ ( i , ( vmin , vmax ) ) for i in array_dict . keys ( ) ] ) <EOL> elif method == '<STR_LIT>' : <EOL> d = { } <EOL> for k , v in array_dict . iteritems ( ) : <EOL> d [ k ] = ( v . min ( ) , v . max ( ) ) <EOL> elif hasattr ( method , '<STR_LIT>' ) : <EOL> d = { } <EOL> sorted_keys = sorted ( array_dict . keys ( ) , key = method ) <EOL> for group , keys in itertools . groupby ( sorted_keys , method ) : <EOL> keys = list ( keys ) <EOL> all_arrays = np . concatenate ( [ array_dict [ i ] for i in keys ] ) <EOL> if percentiles : <EOL> vmin = mlab . prctile ( <EOL> all_arrays , percentiles [ <NUM_LIT:0> ] ) <EOL> vmax = mlab . prctile ( <EOL> all_arrays , percentiles [ <NUM_LIT:1> ] ) <EOL> else : <EOL> vmin = all_arrays . min ( ) <EOL> vmax = all_arrays . max ( ) <EOL> for key in keys : <EOL> d [ key ] = ( vmin , vmax ) <EOL> return d <EOL> def ci ( arr , conf = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> m = arr . mean ( axis = <NUM_LIT:0> ) <EOL> n = len ( arr ) <EOL> se = arr . std ( axis = <NUM_LIT:0> ) / np . sqrt ( n ) <EOL> h = se * stats . t . _ppf ( ( <NUM_LIT:1> + conf ) / <NUM_LIT> , n - <NUM_LIT:1> ) <EOL> return m , m - h , m + h <EOL> def nice_log ( x ) : <EOL> """<STR_LIT>""" <EOL> neg = x < <NUM_LIT:0> <EOL> xi = np . log2 ( np . abs ( x ) + <NUM_LIT:1> ) <EOL> xi [ neg ] = - xi [ neg ] <EOL> return xi <EOL> def tip_zscores ( a ) : <EOL> """<STR_LIT>""" <EOL> weighted = a * a . mean ( axis = <NUM_LIT:0> ) <EOL> scores = weighted . sum ( axis = <NUM_LIT:1> ) <EOL> zscores = ( scores - scores . mean ( ) ) / scores . std ( ) <EOL> return zscores <EOL> def fdrcorrection ( pvals , alpha = <NUM_LIT> , method = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> pvals = np . asarray ( pvals ) <EOL> pvals_sortind = np . argsort ( pvals ) <EOL> pvals_sorted = pvals [ pvals_sortind ] <EOL> sortrevind = pvals_sortind . argsort ( ) <EOL> if method in [ '<STR_LIT:i>' , '<STR_LIT>' , '<STR_LIT:p>' , '<STR_LIT>' ] : <EOL> ecdffactor = _ecdf ( pvals_sorted ) <EOL> elif method in [ '<STR_LIT:n>' , '<STR_LIT>' ] : <EOL> cm = np . sum ( <NUM_LIT:1.> / np . arange ( <NUM_LIT:1> , len ( pvals_sorted ) + <NUM_LIT:1> ) ) <EOL> ecdffactor = _ecdf ( pvals_sorted ) / cm <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> reject = pvals_sorted <= ecdffactor * alpha <EOL> if reject . any ( ) : <EOL> rejectmax = max ( np . nonzero ( reject ) [ <NUM_LIT:0> ] ) <EOL> reject [ : rejectmax ] = True <EOL> pvals_corrected_raw = pvals_sorted / ecdffactor <EOL> pvals_corrected = np . minimum . accumulate ( pvals_corrected_raw [ : : - <NUM_LIT:1> ] ) [ : : - <NUM_LIT:1> ] <EOL> pvals_corrected [ pvals_corrected > <NUM_LIT:1> ] = <NUM_LIT:1> <EOL> return reject [ sortrevind ] , pvals_corrected [ sortrevind ] <EOL> def tip_fdr ( a , alpha = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> zscores = tip_zscores ( a ) <EOL> pvals = stats . norm . pdf ( zscores ) <EOL> rejected , fdrs = fdrcorrection ( pvals ) <EOL> return fdrs <EOL> def prepare_logged ( x , y ) : <EOL> """<STR_LIT>""" <EOL> xi = np . log2 ( x ) <EOL> yi = np . log2 ( y ) <EOL> xv = np . isfinite ( xi ) <EOL> yv = np . isfinite ( yi ) <EOL> global_min = min ( xi [ xv ] . min ( ) , yi [ yv ] . min ( ) ) <EOL> global_max = max ( xi [ xv ] . max ( ) , yi [ yv ] . max ( ) ) <EOL> xi [ ~ xv ] = global_min <EOL> yi [ ~ yv ] = global_min <EOL> return xi , yi <EOL> def new_shell ( figsize = ( <NUM_LIT:5> , <NUM_LIT:12> ) , strip = False , height_ratios = ( <NUM_LIT:4> , <NUM_LIT:1> ) , <EOL> width_ratios = ( <NUM_LIT:4> , <NUM_LIT:1> ) , subplot_params = None ) : <EOL> if subplot_params is None : <EOL> subplot_params = { } <EOL> fig = plt . figure ( figsize = figsize ) <EOL> gs = gridspec . GridSpec ( <EOL> len ( height_ratios ) , <EOL> len ( width_ratios ) , <EOL> height_ratios = height_ratios , <EOL> width_ratios = width_ratios , <EOL> ** subplot_params ) <EOL> fig . array_axes = plt . subplot ( gs [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> if strip : <EOL> fig . strip_axes = plt . subplot ( gs [ <NUM_LIT:0> , <NUM_LIT:1> ] , sharey = fig . array_axes ) <EOL> fig . line_axes = plt . subplot ( gs [ <NUM_LIT:1> , <NUM_LIT:0> ] , sharex = fig . array_axes ) <EOL> fig . cax = plt . subplot ( gs [ <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> fig . gs = gs <EOL> return fig <EOL> def matrix_and_line_shell ( figsize = ( <NUM_LIT:5> , <NUM_LIT:12> ) , strip = False ) : <EOL> """<STR_LIT>""" <EOL> fig = plt . figure ( figsize = figsize ) <EOL> if strip : <EOL> STRIP_COLS = <NUM_LIT:1> <EOL> else : <EOL> STRIP_COLS = <NUM_LIT:0> <EOL> ROWS = <NUM_LIT:4> <EOL> COLS = <NUM_LIT:8> + STRIP_COLS <EOL> MAT_COLS = <NUM_LIT:7> <EOL> MAT_ROWS = <NUM_LIT:3> <EOL> LINE_ROWS = ROWS - MAT_ROWS <EOL> mat_ax = plt . subplot2grid ( <EOL> shape = ( ROWS , COLS ) , <EOL> loc = ( <NUM_LIT:0> , STRIP_COLS ) , <EOL> rowspan = MAT_ROWS , <EOL> colspan = MAT_COLS , <EOL> ) <EOL> line_ax = plt . subplot2grid ( <EOL> shape = ( ROWS , COLS ) , <EOL> loc = ( MAT_ROWS , STRIP_COLS ) , <EOL> rowspan = LINE_ROWS , <EOL> colspan = MAT_COLS , <EOL> sharex = mat_ax ) <EOL> if strip : <EOL> strip_ax = plt . subplot2grid ( <EOL> shape = ( ROWS , COLS ) , <EOL> loc = ( <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> rowspan = MAT_ROWS , <EOL> colspan = STRIP_COLS , <EOL> sharey = mat_ax , <EOL> ) <EOL> else : <EOL> strip_ax = None <EOL> cax = plt . subplot2grid ( <EOL> shape = ( ROWS , COLS ) , <EOL> loc = ( ROWS - MAT_ROWS , MAT_COLS + STRIP_COLS ) , <EOL> rowspan = <NUM_LIT:1> , <EOL> colspan = <NUM_LIT:1> , <EOL> ) <EOL> fig . subplots_adjust ( hspace = <NUM_LIT:0.1> , wspace = <NUM_LIT> , right = <NUM_LIT> , left = <NUM_LIT> ) <EOL> return fig , mat_ax , line_ax , strip_ax , cax <EOL> def clustered_sortind ( x , k = <NUM_LIT:10> , scorefunc = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from sklearn . cluster import MiniBatchKMeans <EOL> except ImportError : <EOL> raise ImportError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if isinstance ( k , int ) : <EOL> best_k = k <EOL> else : <EOL> mean_dists = { } <EOL> for _k in k : <EOL> mbk = MiniBatchKMeans ( init = '<STR_LIT>' , n_clusters = _k ) <EOL> mbk . fit ( x ) <EOL> mean_dists [ _k ] = mbk . transform ( x ) . mean ( ) <EOL> best_k = sorted ( mean_dists . items ( ) , key = lambda x : x [ <NUM_LIT:1> ] ) [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> mbk = MiniBatchKMeans ( init = '<STR_LIT>' , n_clusters = best_k ) <EOL> mbk . fit ( x ) <EOL> k = best_k <EOL> labels = mbk . labels_ <EOL> scores = np . zeros ( labels . shape , dtype = float ) <EOL> if not scorefunc : <EOL> def scorefunc ( x ) : <EOL> return x . mean ( axis = <NUM_LIT:0> ) . max ( ) <EOL> for label in range ( k ) : <EOL> ind = labels == label <EOL> score = scorefunc ( x [ ind , : ] ) <EOL> scores [ ind ] = score <EOL> pos = <NUM_LIT:0> <EOL> breaks = [ ] <EOL> ind = np . argsort ( scores ) <EOL> for k , g in itertools . groupby ( labels [ ind ] ) : <EOL> pos += len ( list ( g ) ) <EOL> breaks . append ( pos ) <EOL> return ind , breaks <EOL> def new_clustered_sortind ( x , k = <NUM_LIT:10> , row_key = None , cluster_key = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from sklearn . cluster import MiniBatchKMeans <EOL> except ImportError : <EOL> raise ImportError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if isinstance ( k , int ) : <EOL> best_k = k <EOL> else : <EOL> mean_dists = { } <EOL> for _k in k : <EOL> mbk = MiniBatchKMeans ( init = '<STR_LIT>' , n_clusters = _k ) <EOL> mbk . fit ( x ) <EOL> mean_dists [ _k ] = mbk . transform ( x ) . mean ( ) <EOL> best_k = sorted ( mean_dists . items ( ) , key = lambda x : x [ <NUM_LIT:1> ] ) [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> mbk = MiniBatchKMeans ( init = '<STR_LIT>' , n_clusters = best_k ) <EOL> mbk . fit ( x ) <EOL> k = best_k <EOL> labels = mbk . labels_ <EOL> scores = np . zeros ( labels . shape , dtype = float ) <EOL> if cluster_key : <EOL> def _cluster_key ( i ) : <EOL> return cluster_key ( x [ labels == i , : ] ) <EOL> sorted_labels = sorted ( range ( k ) , key = _cluster_key ) <EOL> else : <EOL> sorted_labels = range ( k ) <EOL> if row_key : <EOL> def _row_key ( i ) : <EOL> return row_key ( x [ i , : ] ) <EOL> final_ind = [ ] <EOL> breaks = [ ] <EOL> pos = <NUM_LIT:0> <EOL> for label in sorted_labels : <EOL> label_inds = np . nonzero ( labels == label ) [ <NUM_LIT:0> ] <EOL> if row_key : <EOL> label_sort_ind = sorted ( label_inds , key = _row_key ) <EOL> else : <EOL> label_sort_ind = label_inds <EOL> for li in label_sort_ind : <EOL> final_ind . append ( li ) <EOL> pos += len ( label_inds ) <EOL> breaks . append ( pos ) <EOL> return np . array ( final_ind ) , np . array ( breaks ) <EOL> def input_ip_plots ( iparr , inputarr , diffed , x , sort_ind , <EOL> prefix = None , limits1 = ( None , None ) , limits2 = ( None , None ) , <EOL> hlines = None , vlines = None ) : <EOL> """<STR_LIT>""" <EOL> gmin = min ( iparr . min ( ) , inputarr . min ( ) ) <EOL> gmax = max ( iparr . max ( ) , inputarr . max ( ) ) <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> ax1 = plt . subplot2grid ( <EOL> ( <NUM_LIT:9> , <NUM_LIT:9> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) , colspan = <NUM_LIT:3> , rowspan = <NUM_LIT:6> ) <EOL> ax2 = plt . subplot2grid ( <EOL> ( <NUM_LIT:9> , <NUM_LIT:9> ) , ( <NUM_LIT:0> , <NUM_LIT:3> ) , colspan = <NUM_LIT:3> , rowspan = <NUM_LIT:6> , sharex = ax1 , sharey = ax1 ) <EOL> ax3 = plt . subplot2grid ( <EOL> ( <NUM_LIT:9> , <NUM_LIT:9> ) , ( <NUM_LIT:0> , <NUM_LIT:6> ) , colspan = <NUM_LIT:3> , rowspan = <NUM_LIT:6> , sharex = ax1 , sharey = ax1 ) <EOL> ax4 = plt . subplot2grid ( ( <NUM_LIT:9> , <NUM_LIT:9> ) , ( <NUM_LIT:6> , <NUM_LIT:3> ) , colspan = <NUM_LIT:3> , rowspan = <NUM_LIT:3> , sharex = ax1 ) <EOL> ax5 = plt . subplot2grid ( ( <NUM_LIT:9> , <NUM_LIT:9> ) , ( <NUM_LIT:6> , <NUM_LIT:6> ) , colspan = <NUM_LIT:3> , rowspan = <NUM_LIT:3> , sharex = ax1 ) <EOL> cax1 = plt . Axes ( fig , rect = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> cax2 = plt . Axes ( fig , rect = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> extent = ( min ( x ) , max ( x ) , <NUM_LIT:0> , diffed . shape [ <NUM_LIT:0> ] ) <EOL> cm = matplotlib . cm . gist_gray <EOL> cm . set_bad ( '<STR_LIT:k>' ) <EOL> cm . set_over ( '<STR_LIT:r>' ) <EOL> cm . set_under ( '<STR_LIT:b>' ) <EOL> limits1 = list ( limits1 ) <EOL> limits2 = list ( limits2 ) <EOL> all_base = np . column_stack ( ( iparr . ravel ( ) , inputarr . ravel ( ) ) ) . ravel ( ) <EOL> if limits1 [ <NUM_LIT:0> ] is None : <EOL> limits1 [ <NUM_LIT:0> ] = mlab . prctile ( <EOL> all_base , <NUM_LIT:1.> / all_base . size ) <EOL> if limits1 [ <NUM_LIT:1> ] is None : <EOL> limits1 [ <NUM_LIT:1> ] = mlab . prctile ( <EOL> all_base , <NUM_LIT:100> - <NUM_LIT:1.> / all_base . size ) <EOL> if limits2 [ <NUM_LIT:0> ] is None : <EOL> limits2 [ <NUM_LIT:0> ] = mlab . prctile ( <EOL> diffed . ravel ( ) , <NUM_LIT:1.> / all_base . size ) <EOL> if limits2 [ <NUM_LIT:1> ] is None : <EOL> limits2 [ <NUM_LIT:1> ] = mlab . prctile ( <EOL> diffed . ravel ( ) , <NUM_LIT:100> - <NUM_LIT:1.> / all_base . size ) <EOL> del all_base <EOL> imshow_kwargs = dict ( <EOL> interpolation = '<STR_LIT>' , <EOL> aspect = '<STR_LIT>' , <EOL> cmap = cm , <EOL> norm = matplotlib . colors . Normalize ( * limits1 ) , <EOL> extent = extent , <EOL> origin = '<STR_LIT>' ) <EOL> diffed_kwargs = imshow_kwargs . copy ( ) <EOL> diffed_kwargs [ '<STR_LIT>' ] = matplotlib . colors . Normalize ( * limits2 ) <EOL> mappable1 = ax1 . imshow ( iparr [ sort_ind , : ] , ** imshow_kwargs ) <EOL> mappable2 = ax2 . imshow ( inputarr [ sort_ind , : ] , ** imshow_kwargs ) <EOL> mappable3 = ax3 . imshow ( ( diffed ) [ sort_ind , : ] , ** diffed_kwargs ) <EOL> ax4 . plot ( x , inputarr . mean ( axis = <NUM_LIT:0> ) , color = '<STR_LIT:k>' , linestyle = '<STR_LIT>' , <EOL> label = '<STR_LIT:input>' ) <EOL> ax4 . plot ( x , iparr . mean ( axis = <NUM_LIT:0> ) , color = '<STR_LIT:k>' , label = '<STR_LIT>' ) <EOL> ax4 . axvline ( <NUM_LIT:0> , color = '<STR_LIT:k>' , linestyle = '<STR_LIT::>' ) <EOL> ax5 . plot ( x , diffed . mean ( axis = <NUM_LIT:0> ) , '<STR_LIT:k>' , label = '<STR_LIT>' ) <EOL> ax5 . axvline ( <NUM_LIT:0> , color = '<STR_LIT:k>' , linestyle = '<STR_LIT::>' ) <EOL> cbar1 = fig . colorbar ( mappable1 , cax1 , orientation = '<STR_LIT>' ) <EOL> cbar2 = fig . colorbar ( mappable3 , cax2 , orientation = '<STR_LIT>' ) <EOL> fig . add_axes ( cax1 ) <EOL> fig . add_axes ( cax2 ) <EOL> ax1 . set_ylabel ( '<STR_LIT>' ) <EOL> plt . setp ( ax2 . get_yticklabels ( ) , visible = False ) <EOL> plt . setp ( ax3 . get_yticklabels ( ) , visible = False ) <EOL> ax4 . set_xlabel ( '<STR_LIT>' ) <EOL> ax4 . set_ylabel ( '<STR_LIT>' ) <EOL> ax5 . set_xlabel ( '<STR_LIT>' ) <EOL> cax1 . set_xlabel ( '<STR_LIT>' ) <EOL> cax2 . set_xlabel ( '<STR_LIT>' ) <EOL> if prefix is None : <EOL> prefix = "<STR_LIT>" <EOL> ax1 . set_title ( '<STR_LIT>' % prefix ) <EOL> ax2 . set_title ( '<STR_LIT>' % prefix ) <EOL> ax3 . set_title ( '<STR_LIT>' ) <EOL> ax5 . yaxis . set_ticks_position ( '<STR_LIT:right>' ) <EOL> ax5 . yaxis . set_label_position ( '<STR_LIT:right>' ) <EOL> ax5 . set_ylabel ( '<STR_LIT>' ) <EOL> ax4 . legend ( loc = '<STR_LIT>' , frameon = False ) <EOL> ax5 . legend ( loc = '<STR_LIT>' , frameon = False ) <EOL> for ax in [ ax1 , ax2 , ax3 , ax4 , ax5 ] : <EOL> ax . axis ( xmin = extent [ <NUM_LIT:0> ] , xmax = extent [ <NUM_LIT:1> ] ) <EOL> if not hlines : <EOL> hlines = [ ] <EOL> if not vlines : <EOL> vlines = [ ] <EOL> for ax in [ ax1 , ax2 , ax3 ] : <EOL> for pos , kwargs in hlines : <EOL> ax . axhline ( pos , ** kwargs ) <EOL> for pos , kwargs in vlines : <EOL> ax . axvline ( pos , ** kwargs ) <EOL> fig . subplots_adjust ( bottom = <NUM_LIT> , top = <NUM_LIT> , hspace = <NUM_LIT> , wspace = <NUM_LIT> ) <EOL> return fig <EOL> def _updatecopy ( orig , update_with , keys = None , override = False ) : <EOL> """<STR_LIT>""" <EOL> d = orig . copy ( ) <EOL> if keys is None : <EOL> keys = update_with . keys ( ) <EOL> for k in keys : <EOL> if k in update_with : <EOL> if k in d and not override : <EOL> continue <EOL> d [ k ] = update_with [ k ] <EOL> return d <EOL> def _clean ( z ) : <EOL> """<STR_LIT>""" <EOL> return z [ np . isfinite ( z ) ] <EOL> class MarginalHistScatter ( object ) : <EOL> def __init__ ( self , ax , hist_size = <NUM_LIT> , pad = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> self . scatter_ax = ax <EOL> self . fig = ax . figure <EOL> self . divider = make_axes_locatable ( self . scatter_ax ) <EOL> self . top_hists = [ ] <EOL> self . right_hists = [ ] <EOL> self . hist_size = hist_size <EOL> self . pad = pad <EOL> self . xfirst_ax = None <EOL> self . yfirst_ax = None <EOL> self . hxs = [ ] <EOL> self . hys = [ ] <EOL> @ property <EOL> def xmax ( self ) : <EOL> return self . scatter_ax . dataLim . xmax <EOL> @ property <EOL> def ymax ( self ) : <EOL> return self . scatter_ax . dataLim . ymax <EOL> @ property <EOL> def xmin ( self ) : <EOL> return self . scatter_ax . dataLim . xmin <EOL> @ property <EOL> def ymin ( self ) : <EOL> return self . scatter_ax . dataLim . ymin <EOL> @ property <EOL> def limits ( self ) : <EOL> return ( self . xmin , self . xmax , self . ymin , self . ymax ) <EOL> def append ( self , x , y , scatter_kwargs , hist_kwargs = None , xhist_kwargs = None , <EOL> yhist_kwargs = None , num_ticks = <NUM_LIT:3> , labels = None , hist_share = False , <EOL> marginal_histograms = True ) : <EOL> """<STR_LIT>""" <EOL> scatter_kwargs = scatter_kwargs or { } <EOL> hist_kwargs = hist_kwargs or { } <EOL> xhist_kwargs = xhist_kwargs or { } <EOL> yhist_kwargs = yhist_kwargs or { } <EOL> yhist_kwargs . update ( dict ( orientation = '<STR_LIT>' ) ) <EOL> coll = self . scatter_ax . scatter ( x , y , ** scatter_kwargs ) <EOL> coll . labels = labels <EOL> if not marginal_histograms : <EOL> return <EOL> xhk = _updatecopy ( hist_kwargs , xhist_kwargs ) <EOL> yhk = _updatecopy ( hist_kwargs , yhist_kwargs ) <EOL> axhistx = self . divider . append_axes ( <EOL> '<STR_LIT>' , size = self . hist_size , <EOL> pad = self . pad , sharex = self . scatter_ax , sharey = self . xfirst_ax ) <EOL> axhisty = self . divider . append_axes ( <EOL> '<STR_LIT:right>' , size = self . hist_size , <EOL> pad = self . pad , sharey = self . scatter_ax , sharex = self . yfirst_ax ) <EOL> axhistx . yaxis . set_major_locator ( <EOL> MaxNLocator ( nbins = num_ticks , prune = '<STR_LIT>' ) ) <EOL> axhisty . xaxis . set_major_locator ( <EOL> MaxNLocator ( nbins = num_ticks , prune = '<STR_LIT>' ) ) <EOL> if not self . xfirst_ax and hist_share : <EOL> self . xfirst_ax = axhistx <EOL> if not self . yfirst_ax and hist_share : <EOL> self . yfirst_ax = axhisty <EOL> self . top_hists . append ( axhistx ) <EOL> self . right_hists . append ( axhisty ) <EOL> hx = _clean ( x ) <EOL> hy = _clean ( y ) <EOL> self . hxs . append ( hx ) <EOL> self . hys . append ( hy ) <EOL> if len ( hx ) > <NUM_LIT:0> : <EOL> if len ( hx ) == <NUM_LIT:1> : <EOL> _xhk = _updatecopy ( orig = xhk , update_with = dict ( bins = [ hx [ <NUM_LIT:0> ] , hx [ <NUM_LIT:0> ] ] ) , keys = [ '<STR_LIT>' ] ) <EOL> axhistx . hist ( hx , ** _xhk ) <EOL> else : <EOL> axhistx . hist ( hx , ** xhk ) <EOL> if len ( hy ) > <NUM_LIT:0> : <EOL> if len ( hy ) == <NUM_LIT:1> : <EOL> _yhk = _updatecopy ( orig = yhk , update_with = dict ( bins = [ hy [ <NUM_LIT:0> ] , hy [ <NUM_LIT:0> ] ] ) , keys = [ '<STR_LIT>' ] ) <EOL> axhisty . hist ( hy , ** _yhk ) <EOL> else : <EOL> axhisty . hist ( hy , ** yhk ) <EOL> for txt in axhisty . get_yticklabels ( ) + axhistx . get_xticklabels ( ) : <EOL> txt . set_visible ( False ) <EOL> for txt in axhisty . get_xticklabels ( ) : <EOL> txt . set_rotation ( - <NUM_LIT> ) <EOL> def add_legends ( self , xhists = True , yhists = False , scatter = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> axs = [ ] <EOL> if xhists : <EOL> axs . extend ( self . hxs ) <EOL> if yhists : <EOL> axs . extend ( self . hys ) <EOL> if scatter : <EOL> axs . extend ( self . ax ) <EOL> for ax in axs : <EOL> ax . legend ( ** kwargs ) </s>
