def butterfly(segment, sensors=None, title=True, ylim=None, # tax=False, xlabel=True, ylabel=True, color=None, **plot_kwargs): """ Creates a butterfly plot Arguments --------- color: (mpl color) default (``None``): use segment color if available, otherwise black; ``True``: alternate colors (mpl default) title: bool or string Title for the axes. If ``True``, the segment's name is used. sensors: None or list of sensor IDs sensors to plot (``None`` = all) ylim: scalar or (min, max) tuple specifying the y-axis limits (the default ``None`` leaves mpl's default limits unaffected) """ if title is True: title = segment.name # create axes # if tax: # fig = P.figure() # x0 = .07 + bool(ylabel)*.05 # x1 = .97 - x0 # y0 = .15 + bool(xlabel)*.05 # y1 = .97 - y0 - bool(title)*.05 # axrect = (x0, y0, x1, y1) # ax = _t_axes(axrect, xmin=segment.tstart, xmax=segment.tend, # ticks=True, vmax=segment.data.max()) # else: fig = _simple_fig(title, xlabel, ylabel)#, titlekwargs, **simple_kwargs) ax = fig.ax _ax_butterfly(ax, segment, sensors=sensors, ylim=ylim, title=title, xlabel=xlabel, ylabel=ylabel, color=color, **plot_kwargs)
def uts(statsSegments, sensor=0, lineprops={}, title=None, legend='lower left', c=None, # list of colors, e.g.: c= ['r','.75','c','m']] tw=None, # time window marktw = None, # [y, t1, t2, c] Mark a time window with a horizontal line legend_ncol=2, legend_fig=False, sensor_name = True, #sensor_name_y = 1.5, figsize=(3.,3.), savepath=False, saveformat='pdf', tax = True, # use T-axes instead of normal axes (for EEG) xlabel="t [seconds]", ylabel=True, test=False, **kwargs): """ Single plot for on or more time-series Arguments --------- spread: all = False: True -> plot all subjects False -> plot mean Also accepts - subdata kwargs - uts plot kwargs: corr: dict: id->value str(label)->value Parasite """ # kwars if 'ROI' in kwargs: pass # sensor = 0 else: kwargs['sensor'] = sensor statsSegments = _keywords_.sub_segments(statsSegments, kwargs) if test: kwargs['test_segment'] = _test(statsSegments) names, s_name, seg_t_start, seg_t_end = _base._get_attributes(statsSegments, sensor) if ylabel is True: ylabel = False if sensor_name == True: sensor_name = s_name if c is not None: lineprops=[{'color':color} for color in c] # e.g.: c= ['r','.75','c','m']] # axes if tax: x0 = .07 + bool(ylabel)*.05 x1 = .97 - x0 y0 = .15 + bool(xlabel)*.05 y1 = .97 - y0 - bool(title)*.05 axrect = (x0, y0, x1, y1) # axrect = (x0, x1, y0, y1) fig = P.figure(figsize=figsize) ax = _t_axes(axrect, xmin=seg_t_start, xmax=seg_t_end, ticks=True) ax.set_xlabel(xlabel) if ylabel not in [False, None]: ax.set_ylabel(ylabel) else: fig = _simple_fig(title, xlabel, ylabel, figsize=figsize)#, titlekwargs, **simple_kwargs) ax = fig.ax # ax = P.axes(axrect) # plot uts segments handles = _ax_utsStats(statsSegments, sensor, ax=ax, lineprops=lineprops, **kwargs) if tw: P.axvspan(tw[0], tw[1], facecolor=(1.,1.,0), edgecolor='y', alpha=1., zorder=-10) # if title is None: # title = "Time Window %s - %s s"%tuple(tw) if sensor_name: #P.text(seg_t_start, sensor_name_y, sensor_name, family='serif', size=12) P.figtext(.01,.85, sensor_name, family='serif', size=12) if marktw: if type(marktw[0]) not in [list, tuple]: marktw = [marktw] for y, t1, t2, c in marktw: ax.plot([t1, t2], [y, y], color=c, marker='|') if tax: if title: P.suptitle(title, size=12, family='serif') if legend: P.figlegend(handles, names, loc=legend, ncol=legend_ncol) else: fig.add_legend_handles(*handles) if legend: fig.legend(loc=legend, fig=legend_fig, zorder=-1, ncol=legend_ncol) fig.finish() if savepath: filename = 'twtv_'+','.join([s.name for s in statsSegments])+'.'+saveformat P.savefig(os.path.join(savepath, filename)) return fig