<s> '''<STR_LIT>''' <EOL> __author__ = "<STR_LIT>" <EOL> __copyright__ = "<STR_LIT>" <EOL> __license__ = "<STR_LIT>" <EOL> __maintainer__ = "<STR_LIT>" <EOL> __email__ = "<STR_LIT>" <EOL> __status__ = "<STR_LIT>" <EOL> import numpy as np <EOL> import matplotlib . colors as mplcolors <EOL> import matplotlib . cm as cm <EOL> import matplotlib . pyplot as plt <EOL> import skspec . config as cnfg <EOL> from skspec . exceptions import badvalue_error <EOL> DEFCOLOR = ( <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) <EOL> _rgb_from_string = mplcolors . ColorConverter ( ) . to_rgb <EOL> class ColorError ( Exception ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def cmget ( color ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> cmap = getattr ( cm , color ) <EOL> except AttributeError : <EOL> raise badvalue_error ( color , '<STR_LIT>' ) <EOL> return cmap <EOL> def diag_line ( ax , ** linekwds ) : <EOL> """<STR_LIT>""" <EOL> linekwds . setdefault ( '<STR_LIT>' , '<STR_LIT::>' ) <EOL> linekwds . setdefault ( '<STR_LIT>' , '<STR_LIT:k>' ) <EOL> linekwds . setdefault ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> ax . plot ( ax . get_xlim ( ) , <EOL> ax . get_ylim ( ) , <EOL> ** linekwds ) <EOL> return ax <EOL> def multi_axes ( count , ** kwargs ) : <EOL> """<STR_LIT:U+0020>""" <EOL> figsize = kwargs . pop ( '<STR_LIT>' , None ) <EOL> ncols = kwargs . pop ( '<STR_LIT>' , cnfg . multicols ) <EOL> if count <= ncols : <EOL> nrows = <NUM_LIT:1> <EOL> ncols = count <EOL> else : <EOL> nrows = int ( count / ncols ) <EOL> if count % ncols : <EOL> nrows += <NUM_LIT:1> <EOL> if figsize : <EOL> fig , axes = splot ( nrows , ncols , figsize = figsize , fig = True ) <EOL> else : <EOL> fig , axes = splot ( nrows , ncols , fig = True ) <EOL> while len ( fig . axes ) > count : <EOL> fig . delaxes ( fig . axes [ - <NUM_LIT:1> ] ) <EOL> return fig , fig . axes , kwargs <EOL> def _parse_names ( names , default_names ) : <EOL> """<STR_LIT>""" <EOL> default_names = list ( default_names ) <EOL> names = list ( names ) <EOL> if names : <EOL> if len ( names ) == len ( default_names ) : <EOL> pass <EOL> elif len ( names ) < len ( default_names ) : <EOL> logger . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( len ( names ) , len ( default_names ) ) ) <EOL> default_names [ <NUM_LIT:0> : len ( names ) ] = names [ : ] <EOL> return default_names <EOL> else : <EOL> logger . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( len ( names ) , len ( default_names ) ) ) <EOL> return names [ <NUM_LIT:0> : len ( default_names ) ] <EOL> else : <EOL> names [ : ] = default_names [ : ] <EOL> return names <EOL> def _annotate_mappable ( df , cmap , axis = <NUM_LIT:0> , vmin = None , vmax = None ) : <EOL> if isinstance ( cmap , basestring ) : <EOL> cmap = cmget ( cmap ) <EOL> if axis != <NUM_LIT:0> and axis != <NUM_LIT:1> : <EOL> raise badvalue_error ( axis , '<STR_LIT>' ) <EOL> if not vmin : <EOL> vmin = min ( df . min ( axis = axis ) ) <EOL> if not vmax : <EOL> vmax = max ( df . max ( axis = axis ) ) <EOL> cNorm = mplcolors . Normalize ( vmin = vmin , vmax = vmax ) <EOL> scalarmap = cm . ScalarMappable ( norm = cNorm , cmap = cmap ) <EOL> scalarmap . set_array ( np . arange ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> return scalarmap , vmin , vmax <EOL> def _df_colormapper ( df , cmap , axis = <NUM_LIT:0> , colorbymax = False , vmin = None , vmax = None ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( cmap , basestring ) : <EOL> cmap = cmget ( cmap ) <EOL> if axis != <NUM_LIT:0> and axis != <NUM_LIT:1> : <EOL> raise badvalue_error ( axis , '<STR_LIT>' ) <EOL> if not vmin : <EOL> try : <EOL> vmin = min ( df . min ( axis = axis ) ) <EOL> except TypeError : <EOL> vmin = df . min ( axis = axis ) <EOL> if not vmax : <EOL> try : <EOL> vmax = max ( df . max ( axis = axis ) ) <EOL> except TypeError : <EOL> vmax = df . max ( axis = axis ) <EOL> cNorm = mplcolors . Normalize ( vmin = vmin , vmax = vmax ) <EOL> scalarmap = cm . ScalarMappable ( norm = cNorm , cmap = cmap ) <EOL> if axis == <NUM_LIT:0> : <EOL> if colorbymax : <EOL> colors = [ scalarmap . to_rgba ( df [ x ] . max ( ) ) for x in df . columns ] <EOL> else : <EOL> colors = [ scalarmap . to_rgba ( x ) for x in <EOL> np . linspace ( vmin , vmax , len ( df . columns ) ) ] <EOL> elif axis == <NUM_LIT:1> : <EOL> if colorbymax : <EOL> colors = [ scalarmap . to_rgba ( df . ix [ x ] . max ( ) ) for x in df . index ] <EOL> else : <EOL> colors = [ scalarmap . to_rgba ( x ) for x in <EOL> np . linspace ( vmin , vmax , len ( df . index ) ) ] <EOL> return colors <EOL> def to_normrgb ( color ) : <EOL> """<STR_LIT>""" <EOL> if color is None : <EOL> color = DEFCOLOR <EOL> if hasattr ( color , '<STR_LIT>' ) : <EOL> if len ( color ) != <NUM_LIT:3> : <EOL> if len ( color ) == <NUM_LIT:4> : <EOL> color = color [ <NUM_LIT:0> : <NUM_LIT:3> ] <EOL> else : <EOL> raise ColorError ( "<STR_LIT>" <EOL> "<STR_LIT>" % len ( color ) ) <EOL> r , g , b = color <EOL> if r <= <NUM_LIT:1> and g <= <NUM_LIT:1> and b <= <NUM_LIT:1> : <EOL> return ( r , g , b ) <EOL> else : <EOL> r , g , b = map ( _pix_norm , ( r , g , b ) ) <EOL> return ( r , g , b ) <EOL> if isinstance ( color , basestring ) : <EOL> if color == '<STR_LIT>' : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> return _rgb_from_string ( color ) <EOL> if isinstance ( color , int ) : <EOL> color = float ( color ) <EOL> if isinstance ( color , float ) : <EOL> if color > <NUM_LIT:1> : <EOL> color = _pix_norm ( color ) <EOL> return ( color , color , color ) <EOL> if isinstance ( color , bool ) : <EOL> if color : <EOL> return ( <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:1.> ) <EOL> return ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> raise ColorError ( ERRORMESSAGE ) <EOL> def _uvvis_colors ( df , delim = '<STR_LIT::>' ) : <EOL> '''<STR_LIT>''' <EOL> colors = [ ] <EOL> cNorm = mplcolors . Normalize ( vmin = <NUM_LIT> , vmax = <NUM_LIT> ) <EOL> scalarmap = cm . ScalarMappable ( norm = cNorm , cmap = cm . jet ) <EOL> for rng in df . index : <EOL> start , stop = rng . split ( delim ) <EOL> colors . append ( scalarmap . to_rgba ( <NUM_LIT:0.5> * ( float ( stop ) + float ( start ) ) ) ) <EOL> return colors <EOL> def splot ( * args , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> flatten = kwds . pop ( '<STR_LIT>' , True ) <EOL> _return_fig = kwds . pop ( '<STR_LIT>' , False ) <EOL> fig , args = plt . subplots ( * args , ** kwds ) <EOL> if not hasattr ( args , '<STR_LIT>' ) : <EOL> args = [ args ] <EOL> try : <EOL> args = [ ax . axes for ax in args ] <EOL> except Exception : <EOL> if flatten : <EOL> args = [ ax . axes for row in args for ax in row ] <EOL> else : <EOL> args = [ tuple ( ax . axes for ax in row ) for row in args ] <EOL> if _return_fig : <EOL> return ( fig , args ) <EOL> else : <EOL> return args <EOL> def hide_axis ( ax , axis = '<STR_LIT:x>' , axislabel = True , ticklabels = True , ticks = False , <EOL> hide_everything = False ) : <EOL> """<STR_LIT>""" <EOL> if axis not in [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT>' ] : <EOL> raise AttributeError ( '<STR_LIT>' ) <EOL> axis_to_modify = [ ] <EOL> if hide_everything : <EOL> ticks = True ; axislabel = True ; ticklabels = True <EOL> if axis == '<STR_LIT:x>' or axis == '<STR_LIT>' : <EOL> axis_to_modify . append ( ax . get_xaxis ( ) ) <EOL> if axislabel : <EOL> ax . set_xlabel ( '<STR_LIT>' ) <EOL> if axis == '<STR_LIT:y>' or axis == '<STR_LIT>' : <EOL> axis_to_modify . append ( ax . get_yaxis ( ) ) <EOL> if axislabel : <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> for an_axis in axis_to_modify : <EOL> if ticklabels : <EOL> an_axis . set_ticklabels ( [ ] ) <EOL> if ticks : <EOL> an_axis . set_ticks ( [ ] ) <EOL> return ax <EOL> def invert_ax ( ax ) : <EOL> """<STR_LIT>""" <EOL> for line in ax . lines : <EOL> xd = line . get_xdata ( ) <EOL> yd = line . get_ydata ( ) <EOL> line . set_xdata ( yd ) <EOL> line . set_ydata ( xd ) <EOL> xlim = ax . get_xlim ( ) <EOL> ylim = ax . get_ylim ( ) <EOL> ylim = ( ylim [ - <NUM_LIT:1> ] , ylim [ <NUM_LIT:0> ] ) <EOL> ax . set_xlim ( ylim ) <EOL> ax . set_ylim ( xlim ) <EOL> return ax <EOL> def easy_legend ( ax , fancy = True , position = '<STR_LIT>' , ** legendkwds ) : <EOL> '''<STR_LIT>''' <EOL> ir = lambda x : int ( round ( x ) ) <EOL> position = position . lower ( ) <EOL> legendkwds [ '<STR_LIT>' ] = <NUM_LIT:3> <EOL> if position not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:left>' , '<STR_LIT:right>' ] : <EOL> raise badvalue_error ( position , '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in legendkwds : <EOL> if position == '<STR_LIT>' or position == '<STR_LIT>' : <EOL> if len ( ax . lines ) < <NUM_LIT:4> : <EOL> ncol = len ( ax . lines ) <EOL> else : <EOL> ncol = <NUM_LIT:4> <EOL> else : <EOL> ncol = ir ( len ( ax . lines ) / <NUM_LIT> ) <EOL> if ncol == <NUM_LIT:0> : <EOL> ncol = <NUM_LIT:1> <EOL> legendkwds [ '<STR_LIT>' ] = ncol <EOL> box = ax . get_position ( ) <EOL> if '<STR_LIT>' not in legendkwds : <EOL> if position == '<STR_LIT>' : <EOL> '''<STR_LIT>''' <EOL> if ax . get_title ( ) == '<STR_LIT>' : <EOL> bbox_to_anchor = ( <NUM_LIT> , <NUM_LIT> ) <EOL> else : <EOL> bbox_to_anchor = ( <NUM_LIT> , <NUM_LIT> ) <EOL> elif position == '<STR_LIT>' : <EOL> '''<STR_LIT>''' <EOL> if ax . get_xlabel ( ) == '<STR_LIT>' : <EOL> bbox_to_anchor = ( <NUM_LIT> , - <NUM_LIT> ) <EOL> else : <EOL> bbox_to_anchor = ( <NUM_LIT> , - <NUM_LIT> ) <EOL> elif position == '<STR_LIT:right>' : <EOL> '''<STR_LIT>''' <EOL> bbox_to_anchor = ( <NUM_LIT> , <NUM_LIT:0.0> ) <EOL> elif position == '<STR_LIT:left>' : <EOL> '''<STR_LIT>''' <EOL> if ax . get_ylabel ( ) == '<STR_LIT>' : <EOL> bbox_to_anchor = ( - <NUM_LIT> , <NUM_LIT:1.0> ) <EOL> else : <EOL> bbox_to_anchor = ( - <NUM_LIT> , <NUM_LIT:1.0> ) <EOL> legendkwds [ '<STR_LIT>' ] = bbox_to_anchor <EOL> if fancy and '<STR_LIT>' not in legendkwds and '<STR_LIT>' not in legendkwds : <EOL> legendkwds [ '<STR_LIT>' ] = True <EOL> legendkwds [ '<STR_LIT>' ] = True <EOL> if '<STR_LIT>' not in legendkwds : <EOL> legendkwds [ '<STR_LIT>' ] = <NUM_LIT:0.0> <EOL> ax . legend ( ** legendkwds ) <EOL> return ax </s>
