<s> from __future__ import division <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib . colors import LinearSegmentedColormap <EOL> try : <EOL> from ipywidgets import interact , FloatSlider , IntSlider <EOL> except ImportError : <EOL> try : <EOL> from IPython . html . widgets import interact , FloatSlider , IntSlider <EOL> except ImportError : <EOL> try : <EOL> from IPython . html . widgets import ( interact , <EOL> FloatSliderWidget as FloatSlider , <EOL> IntSliderWidget as IntSlider ) <EOL> except ImportError : <EOL> pass <EOL> from . miscplot import palplot <EOL> from . palettes import ( color_palette , dark_palette , light_palette , <EOL> diverging_palette , cubehelix_palette ) <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> def _init_mutable_colormap ( ) : <EOL> """<STR_LIT>""" <EOL> greys = color_palette ( "<STR_LIT>" , <NUM_LIT> ) <EOL> cmap = LinearSegmentedColormap . from_list ( "<STR_LIT>" , greys ) <EOL> cmap . _init ( ) <EOL> cmap . _set_extremes ( ) <EOL> return cmap <EOL> def _update_lut ( cmap , colors ) : <EOL> """<STR_LIT>""" <EOL> cmap . _lut [ : <NUM_LIT> ] = colors <EOL> cmap . _set_extremes ( ) <EOL> def _show_cmap ( cmap ) : <EOL> """<STR_LIT>""" <EOL> from . rcmod import axes_style <EOL> with axes_style ( "<STR_LIT>" ) : <EOL> f , ax = plt . subplots ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> ax . set ( xticks = [ ] , yticks = [ ] ) <EOL> x = np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) [ np . newaxis , : ] <EOL> ax . pcolormesh ( x , cmap = cmap ) <EOL> def choose_colorbrewer_palette ( data_type , as_cmap = False ) : <EOL> """<STR_LIT>""" <EOL> if data_type . startswith ( "<STR_LIT:q>" ) and as_cmap : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> pal = [ ] <EOL> if as_cmap : <EOL> cmap = _init_mutable_colormap ( ) <EOL> if data_type . startswith ( "<STR_LIT:s>" ) : <EOL> opts = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> variants = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> @ interact <EOL> def choose_sequential ( name = opts , n = ( <NUM_LIT:2> , <NUM_LIT> ) , <EOL> desat = FloatSlider ( min = <NUM_LIT:0> , max = <NUM_LIT:1> , value = <NUM_LIT:1> ) , <EOL> variant = variants ) : <EOL> if variant == "<STR_LIT>" : <EOL> name += "<STR_LIT>" <EOL> elif variant == "<STR_LIT>" : <EOL> name += "<STR_LIT>" <EOL> if as_cmap : <EOL> colors = color_palette ( name , <NUM_LIT> , desat ) <EOL> _update_lut ( cmap , np . c_ [ colors , np . ones ( <NUM_LIT> ) ] ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = color_palette ( name , n , desat ) <EOL> palplot ( pal ) <EOL> elif data_type . startswith ( "<STR_LIT:d>" ) : <EOL> opts = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> variants = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> @ interact <EOL> def choose_diverging ( name = opts , n = ( <NUM_LIT:2> , <NUM_LIT:16> ) , <EOL> desat = FloatSlider ( min = <NUM_LIT:0> , max = <NUM_LIT:1> , value = <NUM_LIT:1> ) , <EOL> variant = variants ) : <EOL> if variant == "<STR_LIT>" : <EOL> name += "<STR_LIT>" <EOL> if as_cmap : <EOL> colors = color_palette ( name , <NUM_LIT> , desat ) <EOL> _update_lut ( cmap , np . c_ [ colors , np . ones ( <NUM_LIT> ) ] ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = color_palette ( name , n , desat ) <EOL> palplot ( pal ) <EOL> elif data_type . startswith ( "<STR_LIT:q>" ) : <EOL> opts = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> @ interact <EOL> def choose_qualitative ( name = opts , n = ( <NUM_LIT:2> , <NUM_LIT:16> ) , <EOL> desat = FloatSlider ( min = <NUM_LIT:0> , max = <NUM_LIT:1> , value = <NUM_LIT:1> ) ) : <EOL> pal [ : ] = color_palette ( name , n , desat ) <EOL> palplot ( pal ) <EOL> if as_cmap : <EOL> return cmap <EOL> return pal <EOL> def choose_dark_palette ( input = "<STR_LIT>" , as_cmap = False ) : <EOL> """<STR_LIT>""" <EOL> pal = [ ] <EOL> if as_cmap : <EOL> cmap = _init_mutable_colormap ( ) <EOL> if input == "<STR_LIT>" : <EOL> @ interact <EOL> def choose_dark_palette_rgb ( r = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> g = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> b = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> n = ( <NUM_LIT:3> , <NUM_LIT> ) ) : <EOL> color = r , g , b <EOL> if as_cmap : <EOL> colors = dark_palette ( color , <NUM_LIT> , input = "<STR_LIT>" ) <EOL> _update_lut ( cmap , colors ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = dark_palette ( color , n , input = "<STR_LIT>" ) <EOL> palplot ( pal ) <EOL> elif input == "<STR_LIT>" : <EOL> @ interact <EOL> def choose_dark_palette_hls ( h = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> l = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> s = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> n = ( <NUM_LIT:3> , <NUM_LIT> ) ) : <EOL> color = h , l , s <EOL> if as_cmap : <EOL> colors = dark_palette ( color , <NUM_LIT> , input = "<STR_LIT>" ) <EOL> _update_lut ( cmap , colors ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = dark_palette ( color , n , input = "<STR_LIT>" ) <EOL> palplot ( pal ) <EOL> elif input == "<STR_LIT>" : <EOL> @ interact <EOL> def choose_dark_palette_husl ( h = ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> s = ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> l = ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> n = ( <NUM_LIT:3> , <NUM_LIT> ) ) : <EOL> color = h , s , l <EOL> if as_cmap : <EOL> colors = dark_palette ( color , <NUM_LIT> , input = "<STR_LIT>" ) <EOL> _update_lut ( cmap , colors ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = dark_palette ( color , n , input = "<STR_LIT>" ) <EOL> palplot ( pal ) <EOL> if as_cmap : <EOL> return cmap <EOL> return pal <EOL> def choose_light_palette ( input = "<STR_LIT>" , as_cmap = False ) : <EOL> """<STR_LIT>""" <EOL> pal = [ ] <EOL> if as_cmap : <EOL> cmap = _init_mutable_colormap ( ) <EOL> if input == "<STR_LIT>" : <EOL> @ interact <EOL> def choose_light_palette_rgb ( r = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> g = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> b = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> n = ( <NUM_LIT:3> , <NUM_LIT> ) ) : <EOL> color = r , g , b <EOL> if as_cmap : <EOL> colors = light_palette ( color , <NUM_LIT> , input = "<STR_LIT>" ) <EOL> _update_lut ( cmap , colors ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = light_palette ( color , n , input = "<STR_LIT>" ) <EOL> palplot ( pal ) <EOL> elif input == "<STR_LIT>" : <EOL> @ interact <EOL> def choose_light_palette_hls ( h = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> l = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> s = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> n = ( <NUM_LIT:3> , <NUM_LIT> ) ) : <EOL> color = h , l , s <EOL> if as_cmap : <EOL> colors = light_palette ( color , <NUM_LIT> , input = "<STR_LIT>" ) <EOL> _update_lut ( cmap , colors ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = light_palette ( color , n , input = "<STR_LIT>" ) <EOL> palplot ( pal ) <EOL> elif input == "<STR_LIT>" : <EOL> @ interact <EOL> def choose_light_palette_husl ( h = ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> s = ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> l = ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> n = ( <NUM_LIT:3> , <NUM_LIT> ) ) : <EOL> color = h , s , l <EOL> if as_cmap : <EOL> colors = light_palette ( color , <NUM_LIT> , input = "<STR_LIT>" ) <EOL> _update_lut ( cmap , colors ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = light_palette ( color , n , input = "<STR_LIT>" ) <EOL> palplot ( pal ) <EOL> if as_cmap : <EOL> return cmap <EOL> return pal <EOL> def choose_diverging_palette ( as_cmap = False ) : <EOL> """<STR_LIT>""" <EOL> pal = [ ] <EOL> if as_cmap : <EOL> cmap = _init_mutable_colormap ( ) <EOL> @ interact <EOL> def choose_diverging_palette ( h_neg = IntSlider ( min = <NUM_LIT:0> , <EOL> max = <NUM_LIT> , <EOL> value = <NUM_LIT> ) , <EOL> h_pos = IntSlider ( min = <NUM_LIT:0> , <EOL> max = <NUM_LIT> , <EOL> value = <NUM_LIT:10> ) , <EOL> s = IntSlider ( min = <NUM_LIT:0> , max = <NUM_LIT> , value = <NUM_LIT> ) , <EOL> l = IntSlider ( min = <NUM_LIT:0> , max = <NUM_LIT> , value = <NUM_LIT:50> ) , <EOL> sep = IntSlider ( min = <NUM_LIT:1> , max = <NUM_LIT:50> , value = <NUM_LIT:10> ) , <EOL> n = ( <NUM_LIT:2> , <NUM_LIT:16> ) , <EOL> center = [ "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> if as_cmap : <EOL> colors = diverging_palette ( h_neg , h_pos , s , l , sep , <NUM_LIT> , center ) <EOL> _update_lut ( cmap , colors ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = diverging_palette ( h_neg , h_pos , s , l , sep , n , center ) <EOL> palplot ( pal ) <EOL> if as_cmap : <EOL> return cmap <EOL> return pal <EOL> def choose_cubehelix_palette ( as_cmap = False ) : <EOL> """<STR_LIT>""" <EOL> pal = [ ] <EOL> if as_cmap : <EOL> cmap = _init_mutable_colormap ( ) <EOL> @ interact <EOL> def choose_cubehelix ( n_colors = IntSlider ( min = <NUM_LIT:2> , max = <NUM_LIT:16> , value = <NUM_LIT:9> ) , <EOL> start = FloatSlider ( min = <NUM_LIT:0> , max = <NUM_LIT:3> , value = <NUM_LIT:0> ) , <EOL> rot = FloatSlider ( min = - <NUM_LIT:1> , max = <NUM_LIT:1> , value = <NUM_LIT> ) , <EOL> gamma = FloatSlider ( min = <NUM_LIT:0> , max = <NUM_LIT:5> , value = <NUM_LIT:1> ) , <EOL> hue = FloatSlider ( min = <NUM_LIT:0> , max = <NUM_LIT:1> , value = <NUM_LIT> ) , <EOL> light = FloatSlider ( min = <NUM_LIT:0> , max = <NUM_LIT:1> , value = <NUM_LIT> ) , <EOL> dark = FloatSlider ( min = <NUM_LIT:0> , max = <NUM_LIT:1> , value = <NUM_LIT> ) , <EOL> reverse = False ) : <EOL> if as_cmap : <EOL> colors = cubehelix_palette ( <NUM_LIT> , start , rot , gamma , <EOL> hue , light , dark , reverse ) <EOL> _update_lut ( cmap , np . c_ [ colors , np . ones ( <NUM_LIT> ) ] ) <EOL> _show_cmap ( cmap ) <EOL> else : <EOL> pal [ : ] = cubehelix_palette ( n_colors , start , rot , gamma , <EOL> hue , light , dark , reverse ) <EOL> palplot ( pal ) <EOL> if as_cmap : <EOL> return cmap <EOL> return pal </s>
