def p_explore(dd): ''' plot the results of f_explore''' nt = dd.shape[0] nx = dd.shape[1] xx = () yy = () for i in range(nx): xx = xx + (dd[:, 0, i, 0], ) yy = yy + (dd[:, 1, i, 0], ) xx = xx + (dd[:, 0, i, 1], ) yy = yy + (dd[:, 1, i, 1], ) pd = pt.Paradraw() pd.x_label = '$x_1$' pd.y_label = '$x_2$' pd.marks = ['k'] pt.multiplot2(xx, yy, pd) return xx, yy
def plot_clusters(w1, w2): ind0 = np.where(labels == 0)[0] ind1 = np.where(labels == 1)[0] ind2 = np.where(labels == 2)[0] vocab_list = tfidf_vocab.tolist() try: w1 = int(w1) indword1 = w1 except: #w1 is a string, not an integerer index1 = vocab_list.index(w1) indword1 = np.where(tfidf_index_sorted_weights == index1)[0][0] # try: w2 = int(w2) indword2 = w2 except: #w2 is a string, not an integerer index2 = vocab_list.index(w2) indword2 = np.where(tfidf_index_sorted_weights == index2)[0][0] print(indword1, indword2) # pd = pt.Paradraw() pd.title = tfidf_vocab[tfidf_index_sorted_weights[ indword1]] + ' ' + tfidf_vocab[tfidf_index_sorted_weights[indword2]] pd.x_label = tfidf_vocab[tfidf_index_sorted_weights[indword1]] pd.y_label = tfidf_vocab[tfidf_index_sorted_weights[indword2]] pd.colors = ['r', 'g', 'b'] pd.markers = ['.', '.', '.'] pd.marks = ['', '', ''] pd.markeredge = True pd.markerssize = [8, 8, 8] pd.thickness = [18, 18, 18] pd.legend = ['cluster 1', 'cluster 2', 'cluster 3'] datax = [ most_sig_array[:, indword1][ind0], most_sig_array[:, indword1][ind1], most_sig_array[:, indword1][ind2] ] datay = [ most_sig_array[:, indword2][ind0], most_sig_array[:, indword2][ind1], most_sig_array[:, indword2][ind2] ] pt.multiplot2(datax, datay, pd)
def graph_distrib(graph, plot=False, kmax=None): if kmax is None: k = np.arange(np.max(graph) + 1) else: k = np.arange(kmax + 1) pk = np.zeros(len(k)) for g in graph: if kmax is None: pk[g] += 1 else: if g < kmax + 1: pk[g] += 1 k = k[1:] pk = pk[1:] pk = 1. * pk / np.sum(pk) pk[pk == 0.] = np.min(pk[np.nonzero(pk)]) / 10. A = np.ones((len(k) - 2, 2)) A[:, 1] = k[1:-1] logpk = np.log(pk[1:-1]) mloga, lambda_ = -np.linalg.lstsq(A, logpk)[0][:] a = np.exp(-mloga) print('lambda approx', lambda_) if plot is True: import plot_tools plot_tools.multiplot2( (k, k), (pk, a * np.exp(-lambda_ * k)), plot_tools.Paradraw( marks=['-', '--'], markers=['o', ''], y_scale='log', x_label='k', y_label='P(k)', ax_x_format='%.0f', legend=['', '$\lambda = ' + '{0:.2f}'.format(lambda_) + '$'])) return k, pk, lambda_
def plot(self, style='z'): import plot_tools as pt pd = pt.Paradraw() pd.colors = pt.get_colors(self.n_species) pd.x_scale = 'symlog' pd.y_scale = 'symlog' pd.x_label = 't' if style == 'rates': pd.y_label = 'rates' zs = [self.ts_rates(i)[1:] for i in range(self.n_species)] else: pd.y_label = 'z' zs = [self.ts_Z(i)[1:] for i in range(self.n_species)] time = (self.time[1:], ) * self.n_species figs = pt.multiplot2(time, zs, pd) return figs
def plot_mech(inputs,reaction=None,xlim=None): ploc = inputs['ploc'] outputs = inputs['outputs'] # if reaction is None: if 'main_reaction' not in outputs.keys():order_observability(inputs) reaction = outputs['main_reaction'] #time tmin,tmax = ploc['tmin'],ploc['tmax'] n_s = reaction.n_species tmini = int(np.floor(np.log10(tmin))) tmaxi = int(np.ceil(np.log10(tmax))) #main parameters pd = pt.Paradraw() if n_s<10:pd.legend = [reaction.list[i] for i in xrange(n_s)] pd.x_scale = 'log' if xlim is None: pd.xlim = [tmin,tmax] pd.x_tick_label = [1.*10**i for i in xrange(tmini+1,tmaxi+1,2)] else: pd.xlim = xlim pd.x_label = 'time' import matplotlib.colors as colors pd.colors = [] for ic,c in enumerate(colors.cnames): if ic<n_s:pd.colors.append(str(c)) # pd.colors = ['tan','g','r','b','k','y','magenta','aqua'] cc = [reaction.time_series('concentrations',i) for i in xrange(n_s)] tt = (reaction.time,)*n_s pd.y_label = 'n' pd.ylim = [np.min(cc),np.max(cc)] pt.multiplot2(tt,cc,pd) # zz = [reaction.time_series('z',i) for i in xrange(n_s)] pd.y_scale = 'log' pd.y_label = 'z' pd.ylim = [np.min(zz),np.max(zz)] pt.multiplot2(tt,zz,pd) # pd.y_scale = 'symlog' pd.y_label = 'p rate' pp = [reaction.time_series('rates',i) for i in xrange(n_s)] pd.ylim = [np.min(pp),np.max(pp)] pt.multiplot2(tt,pp,pd)