def plot(data, pull=None, **kwargs): loc = kwargs.get('legend', 'best') title = kwargs.get('title','') FEC = kwargs.get('FEC',False) displayFRET = kwargs.get('show_fret', hasattr(data,'fret')) hold=kwargs.pop('hold', None) if hold is not None: plt.hold(hold) if hasattr(data, '_to_plot'): args, kwargs = data._to_plot() return _subplot(*args, **kwargs) if not pull and hasTrapData(data): pull = TrapData.fromObject(data) if not displayFRET and data is not None: num = 1 elif hasFretData(data): num = 2 else: num = 0 if pull: num += 1 if num==0: raise ValueError("Don't know how to plot argument: missing named fields") layout = iter((num,1,x) for x in range(1,num+1)) ax1 = None if hasFretData(data): plt.subplot(*next(layout)) not hold and plt.cla() plt.hold(True) ax1 = _subplot(data.time, data.donor, label='donor') _subplot(data.time, data.acceptor, label='acceptor', axes=('','counts')) plt.hold(hold) plt.legend(loc=loc,ncol=2,prop={'size':'small'}) if displayFRET: _subplot(data.time, data.fret, layout=next(layout), axes=('Seconds','FRET')) ax2 = None if pull: x_coord,x_label = (pull.ext,'Extension (nm)') if FEC else (pull.sep,'Separation (nm)') ax2 = _subplot(x_coord, pull.f, '.', layout=next(layout), axes=(x_label,'Force (pN)')) first_plot = ax1 if ax1 else ax2 first_plot.set_title(title) plt.show()
def __init__(self, trap, fret, metadata): if trap and not hasTrapData(trap): raise ValueError( "__init__ argument 'trap' <{}> does not have trap data".format(trap)) if fret and not hasFretData(fret): raise ValueError( "__init__ argument 'fret' <{}> does not have fret data".format(fret)) self.trap = trap self._fret = fret self.metadata = nesteddict.from_dict(metadata) self.metadata['trap'] = getattr(trap, 'metadata', nesteddict()) self.metadata['fret'] = getattr(fret, 'metadata', nesteddict()) # Move 'fret' metadata fields found in trap metadata (recorded in .str files) # to the fret.metadata dictionary for key in ifilter(lambda s: s.startswith('fret'), self.metadata['trap'].keys()): self['fret'].update(self.metadata['trap'].pop(key))
def __init__(self, trap, fret, metadata): if trap and not hasTrapData(trap): raise ValueError( "__init__ argument 'trap' <{}> does not have trap data".format( trap)) if fret and not hasFretData(fret): raise ValueError( "__init__ argument 'fret' <{}> does not have fret data".format( fret)) self.trap = trap self._fret = fret self.metadata = nesteddict.from_dict(metadata) self.metadata['trap'] = getattr(trap, 'metadata', nesteddict()) self.metadata['fret'] = getattr(fret, 'metadata', nesteddict()) # Move 'fret' metadata fields found in trap metadata (recorded in .str files) # to the fret.metadata dictionary for key in ifilter(lambda s: s.startswith('fret'), self.metadata['trap'].keys()): self['fret'].update(self.metadata['trap'].pop(key))