<s> """<STR_LIT>""" <EOL> import numpy as _np <EOL> from matplotlib import cm as _cm <EOL> from matplotlib import colors as _colors <EOL> def _rotate_cmap ( cmap , swap_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> """<STR_LIT>""" <EOL> orig_cdict = cmap . _segmentdata . copy ( ) <EOL> cdict = dict ( ) <EOL> cdict [ '<STR_LIT>' ] = [ ( p , c1 , c2 ) <EOL> for ( p , c1 , c2 ) in orig_cdict [ swap_order [ <NUM_LIT:0> ] ] ] <EOL> cdict [ '<STR_LIT>' ] = [ ( p , c1 , c2 ) <EOL> for ( p , c1 , c2 ) in orig_cdict [ swap_order [ <NUM_LIT:1> ] ] ] <EOL> cdict [ '<STR_LIT>' ] = [ ( p , c1 , c2 ) <EOL> for ( p , c1 , c2 ) in orig_cdict [ swap_order [ <NUM_LIT:2> ] ] ] <EOL> return cdict <EOL> def _pigtailed_cmap ( cmap , swap_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> """<STR_LIT>""" <EOL> orig_cdict = cmap . _segmentdata . copy ( ) <EOL> cdict = dict ( ) <EOL> cdict [ '<STR_LIT>' ] = [ ( <NUM_LIT:0.5> * ( <NUM_LIT:1> - p ) , c1 , c2 ) <EOL> for ( p , c1 , c2 ) in reversed ( orig_cdict [ swap_order [ <NUM_LIT:0> ] ] ) ] <EOL> cdict [ '<STR_LIT>' ] = [ ( <NUM_LIT:0.5> * ( <NUM_LIT:1> - p ) , c1 , c2 ) <EOL> for ( p , c1 , c2 ) in reversed ( orig_cdict [ swap_order [ <NUM_LIT:1> ] ] ) ] <EOL> cdict [ '<STR_LIT>' ] = [ ( <NUM_LIT:0.5> * ( <NUM_LIT:1> - p ) , c1 , c2 ) <EOL> for ( p , c1 , c2 ) in reversed ( orig_cdict [ swap_order [ <NUM_LIT:2> ] ] ) ] <EOL> for color in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> cdict [ color ] . extend ( [ ( <NUM_LIT:0.5> * ( <NUM_LIT:1> + p ) , c1 , c2 ) <EOL> for ( p , c1 , c2 ) in orig_cdict [ color ] ] ) <EOL> return cdict <EOL> def _concat_cmap ( cmap1 , cmap2 ) : <EOL> """<STR_LIT>""" <EOL> cdict = dict ( ) <EOL> cdict1 = cmap1 . _segmentdata . copy ( ) <EOL> cdict2 = cmap2 . _segmentdata . copy ( ) <EOL> if not hasattr ( cdict1 [ '<STR_LIT>' ] , '<STR_LIT>' ) : <EOL> for c in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> cdict [ c ] = [ ( <NUM_LIT:0.5> * p , c1 , c2 ) for ( p , c1 , c2 ) in cdict1 [ c ] ] <EOL> else : <EOL> for c in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> cdict [ c ] = [ ] <EOL> ps = _np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:10> ) <EOL> colors = cmap1 ( ps ) <EOL> for p , ( r , g , b , a ) in zip ( ps , colors ) : <EOL> cdict [ '<STR_LIT>' ] . append ( ( <NUM_LIT> * p , r , r ) ) <EOL> cdict [ '<STR_LIT>' ] . append ( ( <NUM_LIT> * p , g , g ) ) <EOL> cdict [ '<STR_LIT>' ] . append ( ( <NUM_LIT> * p , b , b ) ) <EOL> if not hasattr ( cdict2 [ '<STR_LIT>' ] , '<STR_LIT>' ) : <EOL> for c in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> cdict [ c ] . extend ( [ ( <NUM_LIT:0.5> * ( <NUM_LIT:1> + p ) , c1 , c2 ) for ( p , c1 , c2 ) in cdict2 [ c ] ] ) <EOL> else : <EOL> ps = _np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:10> ) <EOL> colors = cmap2 ( ps ) <EOL> for p , ( r , g , b , a ) in zip ( ps , colors ) : <EOL> cdict [ '<STR_LIT>' ] . append ( ( <NUM_LIT> * ( <NUM_LIT:1> + p ) , r , r ) ) <EOL> cdict [ '<STR_LIT>' ] . append ( ( <NUM_LIT> * ( <NUM_LIT:1> + p ) , g , g ) ) <EOL> cdict [ '<STR_LIT>' ] . append ( ( <NUM_LIT> * ( <NUM_LIT:1> + p ) , b , b ) ) <EOL> return cdict <EOL> def alpha_cmap ( color , name = '<STR_LIT>' , alpha_min = <NUM_LIT:0.5> , alpha_max = <NUM_LIT:1.> ) : <EOL> """<STR_LIT>""" <EOL> red , green , blue = _colors . colorConverter . to_rgb ( color ) <EOL> if name == '<STR_LIT>' and hasattr ( color , '<STR_LIT>' ) : <EOL> name = color <EOL> cmapspec = [ ( red , green , blue , <NUM_LIT:1.> ) , <EOL> ( red , green , blue , <NUM_LIT:1.> ) , <EOL> ] <EOL> cmap = _colors . LinearSegmentedColormap . from_list ( <EOL> '<STR_LIT>' % name , cmapspec , _cm . LUTSIZE ) <EOL> cmap . _init ( ) <EOL> cmap . _lut [ : , - <NUM_LIT:1> ] = _np . linspace ( alpha_min , alpha_max , cmap . _lut . shape [ <NUM_LIT:0> ] ) <EOL> cmap . _lut [ - <NUM_LIT:1> , - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> return cmap <EOL> _cmaps_data = dict ( <EOL> cold_hot = _pigtailed_cmap ( _cm . hot ) , <EOL> cold_white_hot = _pigtailed_cmap ( _cm . hot_r ) , <EOL> brown_blue = _pigtailed_cmap ( _cm . bone ) , <EOL> cyan_copper = _pigtailed_cmap ( _cm . copper ) , <EOL> cyan_orange = _pigtailed_cmap ( _cm . YlOrBr_r ) , <EOL> blue_red = _pigtailed_cmap ( _cm . Reds_r ) , <EOL> brown_cyan = _pigtailed_cmap ( _cm . Blues_r ) , <EOL> purple_green = _pigtailed_cmap ( _cm . Greens_r , <EOL> swap_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> purple_blue = _pigtailed_cmap ( _cm . Blues_r , <EOL> swap_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> blue_orange = _pigtailed_cmap ( _cm . Oranges_r , <EOL> swap_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> black_blue = _rotate_cmap ( _cm . hot ) , <EOL> black_purple = _rotate_cmap ( _cm . hot , <EOL> swap_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> black_pink = _rotate_cmap ( _cm . hot , <EOL> swap_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> black_green = _rotate_cmap ( _cm . hot , <EOL> swap_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> black_red = _cm . hot . _segmentdata . copy ( ) , <EOL> ) <EOL> if hasattr ( _cm , '<STR_LIT>' ) : <EOL> _cmaps_data [ '<STR_LIT>' ] = _concat_cmap ( _cm . ocean , _cm . hot_r ) <EOL> if hasattr ( _cm , '<STR_LIT>' ) : <EOL> _cmaps_data [ '<STR_LIT>' ] = _concat_cmap ( _cm . afmhot , _cm . bone_r ) <EOL> _cmaps_data [ '<STR_LIT>' ] = _concat_cmap ( _cm . afmhot_r , _cm . bone ) <EOL> _bwr_data = ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) <EOL> _cmaps_data [ '<STR_LIT>' ] = _colors . LinearSegmentedColormap . from_list ( <EOL> '<STR_LIT>' , _bwr_data ) . _segmentdata . copy ( ) <EOL> _cmap_d = dict ( ) <EOL> for _cmapname in list ( _cmaps_data . keys ( ) ) : <EOL> _cmapname_r = _cmapname + '<STR_LIT>' <EOL> _cmapspec = _cmaps_data [ _cmapname ] <EOL> _cmaps_data [ _cmapname_r ] = _cm . revcmap ( _cmapspec ) <EOL> _cmap_d [ _cmapname ] = _colors . LinearSegmentedColormap ( <EOL> _cmapname , _cmapspec , _cm . LUTSIZE ) <EOL> _cmap_d [ _cmapname_r ] = _colors . LinearSegmentedColormap ( <EOL> _cmapname_r , _cmaps_data [ _cmapname_r ] , <EOL> _cm . LUTSIZE ) <EOL> for color , name in ( ( ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) , '<STR_LIT>' ) , <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , '<STR_LIT>' ) , <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , '<STR_LIT>' ) , <EOL> ) : <EOL> _cmap_d [ '<STR_LIT>' % name ] = alpha_cmap ( color , name = name ) <EOL> _cmap_d [ '<STR_LIT>' % name ] = alpha_cmap ( <EOL> color , alpha_min = <NUM_LIT:0> , <EOL> alpha_max = <NUM_LIT:1> , name = name ) <EOL> locals ( ) . update ( _cmap_d ) <EOL> def dim_cmap ( cmap , factor = <NUM_LIT> , to_white = True ) : <EOL> """<STR_LIT>""" <EOL> assert factor >= <NUM_LIT:0> and factor <= <NUM_LIT:1> , ValueError ( <EOL> '<STR_LIT>' <EOL> % factor ) <EOL> if to_white : <EOL> dimmer = lambda c : <NUM_LIT:1> - factor * ( <NUM_LIT:1> - c ) <EOL> else : <EOL> dimmer = lambda c : factor * c <EOL> cdict = cmap . _segmentdata . copy ( ) <EOL> for c_index , color in enumerate ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> color_lst = list ( ) <EOL> for value , c1 , c2 in cdict [ color ] : <EOL> color_lst . append ( ( value , dimmer ( c1 ) , dimmer ( c2 ) ) ) <EOL> cdict [ color ] = color_lst <EOL> return _colors . LinearSegmentedColormap ( <EOL> '<STR_LIT>' % cmap . name , <EOL> cdict , <EOL> _cm . LUTSIZE ) <EOL> def replace_inside ( outer_cmap , inner_cmap , vmin , vmax ) : <EOL> """<STR_LIT>""" <EOL> assert vmin < vmax , ValueError ( '<STR_LIT>' ) <EOL> assert vmin >= <NUM_LIT:0> , ValueError ( '<STR_LIT>' <EOL> % vmin ) <EOL> assert vmax <= <NUM_LIT:1> , ValueError ( '<STR_LIT>' <EOL> % vmax ) <EOL> outer_cdict = outer_cmap . _segmentdata . copy ( ) <EOL> inner_cdict = inner_cmap . _segmentdata . copy ( ) <EOL> cdict = dict ( ) <EOL> for this_cdict , cmap in [ ( outer_cdict , outer_cmap ) , <EOL> ( inner_cdict , inner_cmap ) ] : <EOL> if hasattr ( this_cdict [ '<STR_LIT>' ] , '<STR_LIT>' ) : <EOL> ps = _np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) <EOL> colors = cmap ( ps ) <EOL> this_cdict [ '<STR_LIT>' ] = list ( ) <EOL> this_cdict [ '<STR_LIT>' ] = list ( ) <EOL> this_cdict [ '<STR_LIT>' ] = list ( ) <EOL> for p , ( r , g , b , a ) in zip ( ps , colors ) : <EOL> this_cdict [ '<STR_LIT>' ] . append ( ( p , r , r ) ) <EOL> this_cdict [ '<STR_LIT>' ] . append ( ( p , g , g ) ) <EOL> this_cdict [ '<STR_LIT>' ] . append ( ( p , b , b ) ) <EOL> for c_index , color in enumerate ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> color_lst = list ( ) <EOL> for value , c1 , c2 in outer_cdict [ color ] : <EOL> if value >= vmin : <EOL> break <EOL> color_lst . append ( ( value , c1 , c2 ) ) <EOL> color_lst . append ( ( vmin , outer_cmap ( vmin ) [ c_index ] , <EOL> inner_cmap ( vmin ) [ c_index ] ) ) <EOL> for value , c1 , c2 in inner_cdict [ color ] : <EOL> if value <= vmin : <EOL> continue <EOL> if value >= vmax : <EOL> break <EOL> color_lst . append ( ( value , c1 , c2 ) ) <EOL> color_lst . append ( ( vmax , inner_cmap ( vmax ) [ c_index ] , <EOL> outer_cmap ( vmax ) [ c_index ] ) ) <EOL> for value , c1 , c2 in outer_cdict [ color ] : <EOL> if value <= vmax : <EOL> continue <EOL> color_lst . append ( ( value , c1 , c2 ) ) <EOL> cdict [ color ] = color_lst <EOL> return _colors . LinearSegmentedColormap ( <EOL> '<STR_LIT>' % ( inner_cmap . name , outer_cmap . name ) , <EOL> cdict , <EOL> _cm . LUTSIZE ) </s>
