def ply_fig(ts, points=False, color='jet', **kwds): """ Convert a timespectra to plotly Figure. Figures can be then directly plotted with plotly.iplot(figure) in the notebook. Use the layout keyword to specify layout parameters; all other keywords are interpreted as line style keywords (color Parameters ---------- points: bool If true, scatter plot; else, lineplots color: str Any valid matplotlib color or colormap. layout: dict Dictionary of keywords that go into layout. """ data = grobs.Data() layoutkwds = kwds.pop('layout', {}) lout = layout(ts, **layoutkwds) # List of colors, either single color or color map try: cmapper = put.cmget(color) #Validate color map except AttributeError: cmapper = [color for i in range(len(ts.columns))] else: cmapper = put._df_colormapper(ts, color, axis=0) # Map colors to rgb cmapper = map(put.to_normrgb, cmapper) # Scale by 255 and string format for plotly def _rgbplotlycolor(rgb): r, g, b = rgb return 'rgb(%s, %s, %s)' % (255.0 * r, 255.0 * g, 255.0 * b) cmapper = map(_rgbplotlycolor, cmapper) if points: tracefcn = make_pointtrace else: tracefcn = make_linetrace for idx, clabel in enumerate(ts): trace = tracefcn( x=np.array( ts.index), # Not necessary to force to np.array.dtype(float) y=np.array(ts[ts.columns[idx]]), name=clabel, color=cmapper[idx], #marker color **kwds) data.append(trace) return grobs.Figure(data=data, layout=lout)
def ply_fig(ts, points=False, color='jet', **kwds): """ Convert a timespectra to plotly Figure. Figures can be then directly plotted with plotly.iplot(figure) in the notebook. Use the layout keyword to specify layout parameters; all other keywords are interpreted as line style keywords (color Parameters ---------- points: bool If true, scatter plot; else, lineplots color: str Any valid matplotlib color or colormap. layout: dict Dictionary of keywords that go into layout. """ data = grobs.Data() layoutkwds = kwds.pop('layout', {}) lout = layout(ts, **layoutkwds) # List of colors, either single color or color map try: cmapper = put.cmget(color) #Validate color map except AttributeError: cmapper = [color for i in range(len(ts.columns))] else: cmapper = put._df_colormapper(ts, color, axis=0) # Map colors to rgb cmapper = map(put.to_normrgb, cmapper) # Scale by 255 and string format for plotly def _rgbplotlycolor(rgb): r,g,b = rgb return 'rgb(%s, %s, %s)' % (255.0*r, 255.0*g, 255.0*b) cmapper = map(_rgbplotlycolor, cmapper) if points: tracefcn = make_pointtrace else: tracefcn = make_linetrace for idx, clabel in enumerate(ts): trace = tracefcn( x = np.array(ts.index), # Not necessary to force to np.array.dtype(float) y = np.array(ts[ts.columns[idx]]), name=clabel, color=cmapper[idx], #marker color **kwds ) data.append(trace) return grobs.Figure(data=data, layout=lout)
def timeplot(ts, **pltkwds): ''' Sends transposed dataframe into _genplot(); however, this is only useful if one wants to plot every single row in a dataframe. For ranges of rows, see spec_utilities.wavelegnth_slices and range_timeplot() below.''' pltkwds['color']=pltkwds.pop('color', _df_colormapper(ts, 'jet', axis=1) ) pltkwds['legend']=pltkwds.pop('legend', True) #Turn legend on xlabel=pltkwds.pop('xlabel', ts.full_timeunit) ylabel=pltkwds.pop('ylabel', ts.full_iunit) title=pltkwds.pop('title', str(ts.name) ) return _genplot(ts.transpose(), xlabel, ylabel, title, **pltkwds)
def timeplot(df, **pltkwds): ''' Sends transposed dataframe into _genplot(); however, this is only useful if one wants to plot every single row in a dataframe. For ranges of rows, see spec_utilities.wavelegnth_slices and range_timeplot() below.''' pltkwds['color']=pltkwds.pop('color', _df_colormapper(df, 'jet', axis=1) ) pltkwds['legend']=pltkwds.pop('legend', True) #Turn legend on pltkwds['ylabel_def']='Intensity' pltkwds['xlabel_def']='Time' pltkwds['title_def']='Intensity vs. Time Plot' return _genplot(df.transpose(), **pltkwds)