def WaitingtimesDistributions(self,waiting_times,rates,trajectory_index,linestyle,linewidth, marker,colors,title,xlabel,ylabel,is_legend,legend_location): """ Plots the waiting times for each reaction in the model. Makes use of ObtainWaitingtimes to derive the waiting times out of the SSA output. Input: - *waiting_times* (dict) - *rates* (list) - *trajectory_index* (integer) - *linestyle* (string) - *linewith* (float) - *marker* (string) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) - *legend_location* [default = 'upper right'] (string/integer) """ plt.figure(self.plotnum) if len(rates) == 1: j = trajectory_index else: j=0 L_legend_names = [] for r_id in rates: L_waiting_times = waiting_times[r_id] # get list of waiting times for a given reaction if len(L_waiting_times) > 1: # At least 2 waiting times are necessary per reaction (x,y,nbins) = LogBin(L_waiting_times,1.5) # Create logarithmic bins (HARDCODED 1.5) if x != None: if colors == None: if j >= len(self.colors): j=0 elif isinstance(colors,list): if j >= len(colors): j=0 elif isinstance(colors,str): colors = [colors] j=0 if colors == None: plt.loglog(x,y,marker,ls = linestyle,lw=linewidth,color = self.colors[j]) else: if clr.is_color_like(colors[j]): plt.loglog(x,y,marker,ls = linestyle,lw=linewidth,color = colors[j]) else: print("*** WARNING ***: '{0}' is not recognized as a valid color code".format(colors[j]) ) plt.loglog(x,y,marker,ls = linestyle,lw=linewidth,color = self.colors[j]) colors = None L_legend_names.append(r_id) j+=1 plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) if is_legend: plt.legend(L_legend_names,numpoints=1,frameon=True,loc=legend_location)
def TimeSeries(self,data,npoints,datatype,labels,trajectory_index,linestyle,linewidth,marker,colors,title,xlabel,ylabel,is_legend,legend_location): """ Tracks the propensities and/or species over time. Input: - *data* (array) - *npoints* (integer) - *datatype* (list) - *labels* (list) - *trajectory_index* (integer) - *linestyle* (string) - *linewidth* (float) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) """ plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] data = getDataForTimeSimPlot(data,npoints,self.quiet) Arr_time = data[:,0] if len(datatype) == 1: j = trajectory_index else: j=0 for i in datatype_indices: y = data[:,i+1] if colors == None: if j >= len(self.colors): j=0 elif isinstance(colors,list): if j >= len(colors): j=0 elif isinstance(colors,str): colors = [colors] j=0 if colors == None: plt.plot(Arr_time,y,marker,ls = linestyle,lw = linewidth,color = self.colors[j]) else: if clr.is_color_like(colors[j]): plt.plot(Arr_time,y,marker,ls = linestyle,lw = linewidth,color = colors[j]) else: print("*** WARNING ***: '{0}' is not recognized as a valid color code".format(colors[j]) ) plt.plot(Arr_time,y,marker,ls = linestyle,lw = linewidth,color = self.colors[j]) colors = None j+=1 if is_legend: plt.legend(datatype,numpoints=1,frameon=True,loc=legend_location) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel)
def AverageTimeSeries(self,means,stds,time,nstd,datatype,labels,linestyle,linewidth,marker,ms,colors,title,xlabel,ylabel,is_legend,legend_location): """ Plots the average and standard deviation of datatype on a regular grid. Input: - *means* (array) - *stds* (array) - *time* (array) - *nstd* (float) - *datatype* (list) - *labels* (list) - *linestyle* (string) - *linewidth* (float) - *marker* (string) - *ms* (float) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) - *legend_location* [default = 'upper right'] (string/integer) """ assert nstd > 0, "Error: The number of STDs must be a value larger than zero" plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] j=0 for i in datatype_indices: if colors == None: if j >= len(self.colors): j=0 elif isinstance(colors,list): if j >= len(colors): j=0 elif isinstance(colors,str): colors = [colors] j=0 # plot with y-axis error bars if colors == None: plt.errorbar(time,means[:,i],yerr = nstd*np.array(stds[:,i]),color = self.colors[j],ls = linestyle,lw=linewidth,marker = marker,ms=ms,label = labels[i]) else: if clr.is_color_like(colors[j]): plt.errorbar(time,means[:,i],yerr = nstd*np.array(stds[:,i]),color = colors[j],ls = linestyle,lw=linewidth,marker = marker,ms=ms,label = labels[i]) else: print("*** WARNING ***: '{0}' is not recognized as a valid color code".format(colors[j]) ) plt.errorbar(time,means[:,i],yerr = nstd*np.array(stds[:,i]),color = self.colors[j],ls = linestyle,lw=linewidth,marker = marker,ms=ms,label = labels[i]) colors = None j+=1 if is_legend: plt.legend(numpoints=1,frameon=True,loc=legend_location) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel)
def Autocorrelations(self,lags,data,datatype,labels,trajectory_index,linestyle,linewidth,marker,colors,title,xlabel,ylabel,is_legend,legend_location): """ Input: - *lags* - *data* (array) - *datatype* (list) - *labels* (list) - *trajectory_index* (integer) - *linestyle* (string) - *linewidth* (float) - *marker* string) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) """ plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] if len(datatype) == 1: j = trajectory_index else: j=0 for i in datatype_indices: if colors == None: if j >= len(self.colors): j=0 elif isinstance(colors,list): if j >= len(colors): j=0 elif isinstance(colors,str): colors = [colors] j=0 y = data[i][0:len(lags)] if colors == None: plt.plot(lags,y,marker,ls = linestyle,lw = linewidth, color = self.colors[j]) else: if clr.is_color_like(colors[j]): plt.plot(lags,y,marker,ls = linestyle,lw = linewidth, color = colors[j]) else: print("*** WARNING ***: '{0}' is not recognized as a valid color code".format(colors[j]) ) plt.plot(lags,y,marker,ls = linestyle,lw = linewidth, color = self.colors[j]) colors = None j+=1 if is_legend: plt.legend(datatype,numpoints=1,frameon=True,loc=legend_location) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel)
def AverageDistributionsCI(self, means, stds, nstd, datatype, labels, colors, title, xlabel, ylabel, is_legend, legend_location): """ Plots the average and standard deviation. Input: - *means* (nested list) - *stds* (nested list) - *nstd* (float) - *labels* (list) - *linestyle* (string) - *linewidth* (float) - *marker* (string) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) - *legend_location* [default = 'upper right'] (string/integer) """ assert nstd > 0, "Error: The number of STDs must be a value larger than zero" plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] for i in datatype_indices: L_s_amount = copy.copy(means[i][0]) L_mu = copy.copy(means[i][1]) L_sigma = copy.copy(stds[i][1]) # Add an additional value L_s_amount.append(L_s_amount[-1] + 1) L_mu.append(L_mu[-1]) L_sigma.append(L_sigma[-1]) X_i = [] Y_i = [] L_errors = [] for j in range(len(L_s_amount)): if (not L_s_amount[j] == L_s_amount[0]) and ( not L_s_amount[j] == L_s_amount[-1]): X_i.append(L_s_amount[j]) Y_i.append(L_mu[j - 1]) L_errors.append(L_sigma[j - 1]) X_i.append(L_s_amount[j]) Y_i.append(L_mu[j]) L_errors.append(L_sigma[j]) X_e = np.concatenate([X_i, X_i[::-1]]) Y_e = np.concatenate([ np.array(Y_i) - nstd * np.array(L_errors), (np.array(Y_i) + nstd * np.array(L_errors))[::-1] ]) if colors == None: if j >= len(self.colors): j = 0 elif isinstance(colors, list): if j >= len(colors): j = 0 elif isinstance(colors, str): colors = [colors] j = 0 if colors == None: plt.fill(X_e - 0.5, Y_e, alpha=.25, ec='None', label='{0} STD confidence interval'.format(nstd), color=self.colors[j]) plt.plot(np.array(X_i) - 0.5, np.array(Y_i), color=self.colors[j]) else: if clr.is_color_like(colors[j]): plt.fill(X_e - 0.5, Y_e, alpha=.25, ec='None', label='{0} STD confidence interval'.format(nstd), color=colors[j]) plt.plot(np.array(X_i) - 0.5, np.array(Y_i), color=colors[j]) else: print( "*** WARNING ***: '{0}' is not recognized as a valid color code" .format(colors[j])) plt.fill(X_e - 0.5, Y_e, alpha=.25, ec='None', label='{0} STD confidence interval'.format(nstd), color=self.colors[j]) plt.plot(np.array(X_i) - 0.5, np.array(Y_i), color=self.colors[j]) colors = None if is_legend: plt.legend(numpoints=1, frameon=True, loc=legend_location) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.title(title)
def AverageDistributions(self, means, stds, nstd, datatype, labels, linestyle, linewidth, marker, colors, title, xlabel, ylabel, is_legend, legend_location): """ Plots the average and standard deviation. Input: - *means* (nested list) - *stds* (nested list) - *nstd* (float) - *labels* (list) - *linestyle* (string) - *linewidth* (float) - *marker* (string) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) - *legend_location* [default = 'upper right'] (string/integer) """ assert nstd > 0, "Error: The number of STDs must be a value larger than zero" plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] j = 0 for i in datatype_indices: if colors == None: if j >= len(self.colors): j = 0 elif isinstance(colors, list): if j >= len(colors): j = 0 elif isinstance(colors, str): colors = [colors] j = 0 if colors == None: plt.errorbar(means[i][0], means[i][1], yerr=nstd * np.array(stds[i][1]), color=self.colors[j], ls=linestyle, lw=linewidth, marker=marker, label=labels[i]) # plot with y-axis error bars else: if clr.is_color_like(colors[j]): plt.errorbar(means[i][0], means[i][1], yerr=nstd * np.array(stds[i][1]), color=colors[j], ls=linestyle, lw=linewidth, marker=marker, label=labels[i]) else: print( "*** WARNING ***: '{0}' is not recognized as a valid color code" .format(colors[j])) plt.errorbar(means[i][0], means[i][1], yerr=nstd * np.array(stds[i][1]), color=self.colors[j], ls=linestyle, lw=linewidth, marker=marker, label=labels[i]) colors = None j += 1 if is_legend: plt.legend(numpoints=1, frameon=True, loc=legend_location) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel)
def WaitingtimesDistributions(self, waiting_times, rates, trajectory_index, linestyle, linewidth, marker, colors, title, xlabel, ylabel, is_legend, legend_location): """ Plots the waiting times for each reaction in the model. Makes use of ObtainWaitingtimes to derive the waiting times out of the SSA output. Input: - *waiting_times* (dict) - *rates* (list) - *trajectory_index* (integer) - *linestyle* (string) - *linewith* (float) - *marker* (string) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) - *legend_location* [default = 'upper right'] (string/integer) """ plt.figure(self.plotnum) if len(rates) == 1: j = trajectory_index else: j = 0 L_legend_names = [] for r_id in rates: L_waiting_times = waiting_times[ r_id] # get list of waiting times for a given reaction if len( L_waiting_times ) > 1: # At least 2 waiting times are necessary per reaction (x, y, nbins) = LogBin( L_waiting_times, 1.5) # Create logarithmic bins (HARDCODED 1.5) if x != None: if colors == None: if j >= len(self.colors): j = 0 elif isinstance(colors, list): if j >= len(colors): j = 0 elif isinstance(colors, str): colors = [colors] j = 0 if colors == None: plt.loglog(x, y, marker, ls=linestyle, lw=linewidth, color=self.colors[j]) else: if clr.is_color_like(colors[j]): plt.loglog(x, y, marker, ls=linestyle, lw=linewidth, color=colors[j]) else: print( "*** WARNING ***: '{0}' is not recognized as a valid color code" .format(colors[j])) plt.loglog(x, y, marker, ls=linestyle, lw=linewidth, color=self.colors[j]) colors = None L_legend_names.append(r_id) j += 1 plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) if is_legend: plt.legend(L_legend_names, numpoints=1, frameon=True, loc=legend_location)
def Distributions(self, distributions, datatype, labels, trajectory_index, linestyle, linewidth, colors, title, xlabel, ylabel, is_legend=True, legend_location='upper right', bin_size=1, histtype='step', orientation='vertical', multiplotting=False): """ Plots the distributions of species and/or propensities Normed=False because the total probability is determined by summation not by integration. Input: - *distributions* (nested list) - *datatype* (list) - *labels* (list) - *trajectory_index* (integer) - *linestyle* (string) - *linewidth* (float) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) - *legend_location* [default = 'upper right'] (string/integer) - *bin_size* (string) [default = 1] - *histtype* (string)) [default = 'step'] - *orientation* (string) [default = 'vertical'] - *multiplotting* (boolean) [default = False] """ plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] if len(datatype) == 1: j = trajectory_index else: j = 0 for i in datatype_indices: dat_min = distributions[i][0].min() dat_max = distributions[i][0].max() n_bins = 1 + (dat_max - dat_min ) / bin_size # Just take one trajectory as reference L_bin_edges = np.linspace(dat_min - bin_size / 2.0, dat_max + bin_size / 2.0, n_bins + 1) if colors == None: if j >= len(self.colors): j = 0 elif isinstance(colors, list): if j >= len(colors): j = 0 elif isinstance(colors, str): colors = [colors] j = 0 if colors == None: output = plt.hist(distributions[i][0], L_bin_edges, weights=distributions[i][1], ls=linestyle, lw=linewidth, color=self.colors[j], histtype=histtype, orientation=orientation, normed=False) else: if clr.is_color_like(colors[j]): output = plt.hist(distributions[i][0], L_bin_edges, weights=distributions[i][1], ls=linestyle, lw=linewidth, color=colors[j], histtype=histtype, orientation=orientation, normed=False) else: print( "*** WARNING ***: '{0}' is not recognized as a valid color code" .format(colors[j])) output = plt.hist(distributions[i][0], L_bin_edges, weights=distributions[i][1], ls=linestyle, lw=linewidth, color=self.colors[j], histtype=histtype, orientation=orientation, normed=False) colors = None j += 1 if is_legend: plt.legend(datatype, numpoints=1, frameon=True, loc=legend_location) plt.title(title) if orientation.lower() == 'horizontal': plt.xlabel(ylabel) plt.ylabel(xlabel) if multiplotting: plt.xticks([0, max(output[0]) * 1.1]) else: plt.xlabel(xlabel) plt.ylabel(ylabel) if multiplotting: plt.yticks([0, max(output[0]) * 1.1])
def Autocorrelations(self, lags, data, datatype, labels, trajectory_index, linestyle, linewidth, marker, colors, title, xlabel, ylabel, is_legend, legend_location): """ Input: - *lags* - *data* (array) - *datatype* (list) - *labels* (list) - *trajectory_index* (integer) - *linestyle* (string) - *linewidth* (float) - *marker* string) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) """ plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] if len(datatype) == 1: j = trajectory_index else: j = 0 for i in datatype_indices: if colors == None: if j >= len(self.colors): j = 0 elif isinstance(colors, list): if j >= len(colors): j = 0 elif isinstance(colors, str): colors = [colors] j = 0 y = data[i][0:len(lags)] if colors == None: plt.plot(lags, y, marker, ls=linestyle, lw=linewidth, color=self.colors[j]) else: if clr.is_color_like(colors[j]): plt.plot(lags, y, marker, ls=linestyle, lw=linewidth, color=colors[j]) else: print( "*** WARNING ***: '{0}' is not recognized as a valid color code" .format(colors[j])) plt.plot(lags, y, marker, ls=linestyle, lw=linewidth, color=self.colors[j]) colors = None j += 1 if is_legend: plt.legend(datatype, numpoints=1, frameon=True, loc=legend_location) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel)
def TimeSeries(self, data, npoints, datatype, labels, trajectory_index, linestyle, linewidth, marker, colors, title, xlabel, ylabel, is_legend, legend_location): """ Tracks the propensities and/or species over time. Input: - *data* (array) - *npoints* (integer) - *datatype* (list) - *labels* (list) - *trajectory_index* (integer) - *linestyle* (string) - *linewidth* (float) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) """ plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] data = getDataForTimeSimPlot(data, npoints, self.quiet) Arr_time = data[:, 0] if len(datatype) == 1: j = trajectory_index else: j = 0 for i in datatype_indices: y = data[:, i + 1] if colors == None: if j >= len(self.colors): j = 0 elif isinstance(colors, list): if j >= len(colors): j = 0 elif isinstance(colors, str): colors = [colors] j = 0 if colors == None: plt.plot(Arr_time, y, marker, ls=linestyle, lw=linewidth, color=self.colors[j]) else: if clr.is_color_like(colors[j]): plt.plot(Arr_time, y, marker, ls=linestyle, lw=linewidth, color=colors[j]) else: print( "*** WARNING ***: '{0}' is not recognized as a valid color code" .format(colors[j])) plt.plot(Arr_time, y, marker, ls=linestyle, lw=linewidth, color=self.colors[j]) colors = None j += 1 if is_legend: plt.legend(datatype, numpoints=1, frameon=True, loc=legend_location) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel)
def AverageDistributionsCI(self,means,stds,nstd,datatype,labels,colors,title,xlabel,ylabel,is_legend,legend_location): """ Plots the average and standard deviation. Input: - *means* (nested list) - *stds* (nested list) - *nstd* (float) - *labels* (list) - *linestyle* (string) - *linewidth* (float) - *marker* (string) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) - *legend_location* [default = 'upper right'] (string/integer) """ assert nstd > 0, "Error: The number of STDs must be a value larger than zero" plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] for i in datatype_indices: L_s_amount = copy.copy(means[i][0]) L_mu = copy.copy(means[i][1]) L_sigma = copy.copy(stds[i][1]) # Add an additional value L_s_amount.append(L_s_amount[-1]+1) L_mu.append(L_mu[-1]) L_sigma.append(L_sigma[-1]) X_i = [] Y_i = [] L_errors = [] for j in range(len(L_s_amount)): if (not L_s_amount[j] == L_s_amount[0]) and (not L_s_amount[j] == L_s_amount[-1]): X_i.append(L_s_amount[j]) Y_i.append(L_mu[j-1]) L_errors.append(L_sigma[j-1]) X_i.append(L_s_amount[j]) Y_i.append(L_mu[j]) L_errors.append(L_sigma[j]) X_e = np.concatenate([X_i, X_i[::-1]]) Y_e = np.concatenate([np.array(Y_i) - nstd*np.array(L_errors) ,(np.array(Y_i) + nstd*np.array(L_errors))[::-1]]) if colors == None: if j >= len(self.colors): j=0 elif isinstance(colors,list): if j >= len(colors): j=0 elif isinstance(colors,str): colors = [colors] j=0 if colors == None: plt.fill(X_e-0.5,Y_e, alpha=.25, ec='None', label='{0} STD confidence interval'.format(nstd),color = self.colors[j]) plt.plot(np.array(X_i)-0.5,np.array(Y_i),color = self.colors[j]) else: if clr.is_color_like(colors[j]): plt.fill(X_e-0.5,Y_e, alpha=.25, ec='None', label='{0} STD confidence interval'.format(nstd),color = colors[j]) plt.plot(np.array(X_i)-0.5,np.array(Y_i),color = colors[j]) else: print("*** WARNING ***: '{0}' is not recognized as a valid color code".format(colors[j]) ) plt.fill(X_e-0.5,Y_e, alpha=.25, ec='None', label='{0} STD confidence interval'.format(nstd),color = self.colors[j]) plt.plot(np.array(X_i)-0.5,np.array(Y_i),color = self.colors[j]) colors = None if is_legend: plt.legend(numpoints=1,frameon=True,loc=legend_location) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.title(title)
def Distributions(self,distributions,datatype,labels,trajectory_index,linestyle,linewidth,colors,title,xlabel,ylabel,is_legend=True,legend_location='upper right',bin_size=1,histtype = 'step',orientation='vertical',multiplotting=False): """ Plots the distributions of species and/or propensities Normed=False because the total probability is determined by summation not by integration. Input: - *distributions* (nested list) - *datatype* (list) - *labels* (list) - *trajectory_index* (integer) - *linestyle* (string) - *linewidth* (float) - *colors* (list) - *title* (string) - *xlabel* (string) - *ylabel* (string) - *is_legend* (boolean) - *legend_location* [default = 'upper right'] (string/integer) - *bin_size* (string) [default = 1] - *histtype* (string)) [default = 'step'] - *orientation* (string) [default = 'vertical'] - *multiplotting* (boolean) [default = False] """ plt.figure(self.plotnum) datatype_indices = [labels.index(Id) for Id in datatype] if len(datatype) == 1: j = trajectory_index else: j=0 for i in datatype_indices: dat_min = distributions[i][0].min() dat_max = distributions[i][0].max() n_bins = 1 + (dat_max-dat_min) /bin_size # Just take one trajectory as reference L_bin_edges = np.linspace(dat_min-bin_size/2.0,dat_max+bin_size/2.0,n_bins+1) if colors == None: if j >= len(self.colors): j=0 elif isinstance(colors,list): if j >= len(colors): j=0 elif isinstance(colors,str): colors = [colors] j=0 if colors == None: output = plt.hist(distributions[i][0],L_bin_edges,weights = distributions[i][1],ls = linestyle,lw = linewidth,color = self.colors[j],histtype = histtype,orientation=orientation,normed=False) else: if clr.is_color_like(colors[j]): output = plt.hist(distributions[i][0],L_bin_edges,weights = distributions[i][1],ls = linestyle,lw = linewidth,color = colors[j],histtype = histtype,orientation=orientation,normed=False) else: print("*** WARNING ***: '{0}' is not recognized as a valid color code".format(colors[j]) ) output = plt.hist(distributions[i][0],L_bin_edges,weights = distributions[i][1],ls = linestyle,lw = linewidth,color = self.colors[j],histtype = histtype,orientation=orientation,normed=False) colors = None j+=1 if is_legend: plt.legend(datatype,numpoints=1,frameon=True,loc=legend_location) plt.title(title) if orientation.lower() == 'horizontal': plt.xlabel(ylabel) plt.ylabel(xlabel) if multiplotting: plt.xticks([0,max(output[0])*1.1]) else: plt.xlabel(xlabel) plt.ylabel(ylabel) if multiplotting: plt.yticks([0,max(output[0])*1.1])