<s> import plotly . graph_objs as grobs <EOL> import numpy as np <EOL> import plot_utils as put <EOL> def make_linetrace ( x , y , ** tracekwargs ) : <EOL> """<STR_LIT>""" <EOL> name = tracekwargs . pop ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> tracekwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return grobs . Scatter ( x = x , <EOL> y = y , <EOL> mode = '<STR_LIT>' , <EOL> name = name , <EOL> marker = grobs . Line ( ** tracekwargs ) <EOL> ) <EOL> def make_pointtrace ( x , y , ** tracekwargs ) : <EOL> """<STR_LIT>""" <EOL> name = tracekwargs . pop ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> tracekwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> tracekwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> tracekwargs . setdefault ( '<STR_LIT:size>' , <NUM_LIT:10> ) <EOL> return grobs . Scatter ( x = x , <EOL> y = y , <EOL> mode = '<STR_LIT>' , <EOL> marker = grobs . Marker ( ** tracekwargs ) <EOL> ) <EOL> def _parsenull ( value ) : <EOL> """<STR_LIT>""" <EOL> if not value : <EOL> value = '<STR_LIT>' <EOL> return value <EOL> def layout ( ts , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> kwargs . setdefault ( '<STR_LIT:title>' , _parsenull ( ts . name ) ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , False ) <EOL> xtitle = _parsenull ( kwargs . pop ( '<STR_LIT>' , ts . specunit ) ) <EOL> ytitle = _parsenull ( kwargs . pop ( '<STR_LIT>' , ts . iunit ) ) <EOL> kwargs [ '<STR_LIT>' ] = grobs . XAxis ( title = xtitle ) <EOL> kwargs [ '<STR_LIT>' ] = grobs . YAxis ( title = ytitle ) <EOL> layout = grobs . Layout ( ** kwargs ) <EOL> axis_style = dict ( zeroline = False , <EOL> gridcolor = '<STR_LIT>' , <EOL> ticks = '<STR_LIT>' , <EOL> ticklen = <NUM_LIT:8> , <EOL> tickwidth = <NUM_LIT> ) <EOL> layout [ '<STR_LIT>' ] . update ( axis_style ) <EOL> layout [ '<STR_LIT>' ] . update ( axis_style ) <EOL> return layout <EOL> def ply_fig ( ts , points = False , color = '<STR_LIT>' , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> data = grobs . Data ( ) <EOL> layoutkwds = kwds . pop ( '<STR_LIT>' , { } ) <EOL> lout = layout ( ts , ** layoutkwds ) <EOL> try : <EOL> cmapper = put . cmget ( color ) <EOL> except AttributeError : <EOL> cmapper = [ color for i in range ( len ( ts . columns ) ) ] <EOL> else : <EOL> cmapper = put . _df_colormapper ( ts , color , axis = <NUM_LIT:0> ) <EOL> cmapper = map ( put . to_normrgb , cmapper ) <EOL> def _rgbplotlycolor ( rgb ) : <EOL> r , g , b = rgb <EOL> return '<STR_LIT>' % ( <NUM_LIT> * r , <NUM_LIT> * g , <NUM_LIT> * b ) <EOL> cmapper = map ( _rgbplotlycolor , cmapper ) <EOL> if points : <EOL> tracefcn = make_pointtrace <EOL> else : <EOL> tracefcn = make_linetrace <EOL> for idx , clabel in enumerate ( ts ) : <EOL> trace = tracefcn ( <EOL> x = np . array ( ts . index ) , <EOL> y = np . array ( ts [ ts . columns [ idx ] ] ) , <EOL> name = clabel , <EOL> color = cmapper [ idx ] , <EOL> ** kwds <EOL> ) <EOL> data . append ( trace ) <EOL> return grobs . Figure ( data = data , layout = lout ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from skspec . data import test_spectra <EOL> ts = test_spectra ( ) <EOL> out = ply_figure ( ts ) <EOL> print tls . get_subplots ( rows = <NUM_LIT:3> , columns = <NUM_LIT:2> , print_grid = True ) <EOL> import plotly . plotly as py <EOL> py . sign_in ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> fig = ply_figure ( ts , color = '<STR_LIT>' , points = True ) <EOL> py . iplot ( fig , filename = '<STR_LIT:foo>' , fileopt = '<STR_LIT>' ) <EOL> print '<STR_LIT>' </s>
