def trace_plots(history, burnin): from rpy import r h = np.array(history) print "{} total, {} burning, {} remaining".format(len(history), burnin, len(history)-burnin) r.par(mfrow=[2,2]) r.acf(h[burnin:]) r.plot(h,xlab='',ylab='',main='') r.abline(v=burnin, col='blue') #r.hist(h[burnin:],breaks=30,xlab='',ylab='',main='histogram') r.plot(r.density(h[burnin:]), xlab='',ylab='',main='density')
def trace_plots(history, burnin): from rpy import r h = np.array(history) print "{} total, {} burning, {} remaining".format(len(history), burnin, len(history) - burnin) r.par(mfrow=[2, 2]) r.acf(h[burnin:]) r.plot(h, xlab='', ylab='', main='') r.abline(v=burnin, col='blue') #r.hist(h[burnin:],breaks=30,xlab='',ylab='',main='histogram') r.plot(r.density(h[burnin:]), xlab='', ylab='', main='density')
def plotBundle(self, bundleD, full_filename, colorsD=None, bundlePointsD=None, legendL=None, title=None, y_max=None): if y_max is None: y_max = 0.4 if legendL is None: legendL = bundleD.keys() legendL.sort() if title is None: title = 'data' bundleIdL = bundleD.keys() bundleIdL.sort() if colorsD is None: colorsL = r.rainbow(len(bundleIdL)) colorsD = dict(zip(bundleIdL, colorsL)) colorsL = [colorsD[x] for x in bundleIdL] time_min = min([len(bundleD[x]) for x in bundleD.keys()]) timeVec = [0.5 * x for x in range(time_min)] try: r.png(full_filename, width=800, height=600) oldPar = r.par(xpd = True, mar = [x + y for (x,y) in zip(r.par()['mar'], [0,0,0,6])]) print 'plot %s' % full_filename r.plot(timeVec, timeVec, type='n', main=title, ylim=(0, y_max), xlab="time in hours after transfection", ylab="Relative Cell Counts", pch=20, lwd=1, lty = 1, cex=1.0, cex_lab=1.2, cex_main=1.5) for bundleId in bundleIdL: if not bundlePointsD is None: r.points(timeVec, bundlePointsD[bundleId], col=colorsD[bundleId], pch=20, lwd=1) r.lines(timeVec, bundlePointsD[bundleId], col=colorsD[bundleId], lwd=1, lty = 1) r.lines(timeVec, bundleD[bundleId], col=colorsD[bundleId], lwd=3, lty = 1) r.legend(max(timeVec) * 1.1, y_max, legend=legendL, fill=colorsL, cex=1.0, bg= 'whitesmoke') r.par(oldPar) r.grid(col="darkgrey") r.dev_off() except: r.dev_off() print full_filename + ' has not been printed.' return
# Make the CanonicalProperties try: cp = CanonicalProperties(options.muninn_log_file, options.which) except CanonicalException, e: print parser.error(e) # Store all the plotting data data = [] # Print which is used print "Using:", cp.fullname # Plot the required output r.pdf(options.output, width=options.width, height=options.height) r.par(cex=options.cex) inv_beta = arange(options.inv_beta_min, options.inv_beta_max, 0.01) beta = 1.0/inv_beta lnZ = vectorize(cp.lnZ)(beta) r.plot(inv_beta, lnZ, type='l', xlab=r("expression(beta**-1)"), ylab=r("""expression(paste("ln ", Z(beta)))""")) data.append((cp.number, "lnZ", (inv_beta, lnZ))) betaF = vectorize(cp.betaF)(beta) r.plot(inv_beta, betaF, type='l', xlab=r("expression(beta**-1)"), ylab=r("expression(F(beta) * beta)")) data.append((cp.number, "betaF", (inv_beta, betaF))) S = vectorize(cp.S)(beta) r.plot(inv_beta, S, type='l', xlab=r("expression(beta**-1)"), ylab=r("expression(S(beta) / k[B])")) data.append((cp.number, "S", (inv_beta, S)))
def plot(outfile, data, out_format='png'): w = int(round(len(data)/4.0)) if out_format == 'png': r.png(outfile, width=w*100, height=1000, res=72) elif out_format == 'pdf': r.pdf(outfile, width=w, height=10) else: raise Exception('Unrecognised format: ' + str(out_format)) print("total: " + str(len(data))) series = [] points = {'translate': [], 'preprocessing': []} for dat in data: points['translate'].append(float(dat['translate'])) points['preprocessing'].append(float(dat['preprocessing'])) xlabels = [] for k, v in data[0].iteritems(): if k not in ["problem", 'translate', 'preprocessing']: series.append(k) points[k] = [] index = 0 for dat in data: for k in series: if dat[k] != 'no-plan': points[k].append(float(dat[k]) + \ points['translate'][index] + \ points['preprocessing'][index]) else: points[k].append(-1000) xlabels.append(dat['problem']) index += 1 max_value = max(iter([max(iter(points[k])) for k in series])) yrange = (0, max_value) legend_labels = [] x = [i for i in range(1,len(points['translate'])+1)] y = [-1000 for i in x] r.par(mar=(7,5,4,2)) r.plot(x, y, main='', xlab="", ylab='', xaxt='n', yaxt='n', pch=0, ylim=yrange, mgp=(5,1,0)) r.mtext("Problem", side=1, line=5) r.mtext("CPU Time (s)", side=2, line=3) pch_start = 1 pch_index = pch_start # plotting "translate" #r.plot(x, points['translate'], main='', # xlab='', ylab='Time (s)', # xaxt='n', yaxt='n', # pch=0, ylim=yrange) #legend_labels.append('translate') r.lines(x, points['translate'], lty=1) # preprocessing -- Removed since it's insignificant #r.points(x, points['preprocessing'], pch=pch_index) #pch_index =+ 1 # planner output for k in series: if k != 'translate' and k != 'preporcessing': r.points(x, points[k], pch=pch_index) pch_index += 1 legend_labels.append("FD+" + k.upper()) # put x-axis labels for i in range(0, len(xlabels)): r.axis(side=1, at=i+1, labels=xlabels[i], las=2) # put y-axis labels base, step = get_y_step(max_value) print("base: " + str(base) + " -- step: " + str(step)) y = base for i in range(0, step): r.axis(side=2, at=y, labels=str(y), las=2) y += base # legend r.legend(1, max_value, legend_labels, pch=[i for i in range(pch_start, pch_index)]) r.dev_off()
def plot(outfile, data, out_format='png'): w = int(round(len(data) / 4.0)) if out_format == 'png': r.png(outfile, width=w * 100, height=1000, res=72) elif out_format == 'pdf': r.pdf(outfile, width=w, height=10) else: raise Exception('Unrecognised format: ' + str(out_format)) print("total: " + str(len(data))) series = [] points = {'translate': [], 'preprocessing': []} for dat in data: points['translate'].append(float(dat['translate'])) points['preprocessing'].append(float(dat['preprocessing'])) xlabels = [] for k, v in data[0].iteritems(): if k not in ["problem", 'translate', 'preprocessing']: series.append(k) points[k] = [] index = 0 for dat in data: for k in series: if dat[k] != 'no-plan': points[k].append(float(dat[k]) + \ points['translate'][index] + \ points['preprocessing'][index]) else: points[k].append(-1000) xlabels.append(dat['problem']) index += 1 max_value = max(iter([max(iter(points[k])) for k in series])) yrange = (0, max_value) legend_labels = [] x = [i for i in range(1, len(points['translate']) + 1)] y = [-1000 for i in x] r.par(mar=(7, 5, 4, 2)) r.plot(x, y, main='', xlab="", ylab='', xaxt='n', yaxt='n', pch=0, ylim=yrange, mgp=(5, 1, 0)) r.mtext("Problem", side=1, line=5) r.mtext("CPU Time (s)", side=2, line=3) pch_start = 1 pch_index = pch_start # plotting "translate" #r.plot(x, points['translate'], main='', # xlab='', ylab='Time (s)', # xaxt='n', yaxt='n', # pch=0, ylim=yrange) #legend_labels.append('translate') r.lines(x, points['translate'], lty=1) # preprocessing -- Removed since it's insignificant #r.points(x, points['preprocessing'], pch=pch_index) #pch_index =+ 1 # planner output for k in series: if k != 'translate' and k != 'preporcessing': r.points(x, points[k], pch=pch_index) pch_index += 1 legend_labels.append("FD+" + k.upper()) # put x-axis labels for i in range(0, len(xlabels)): r.axis(side=1, at=i + 1, labels=xlabels[i], las=2) # put y-axis labels base, step = get_y_step(max_value) print("base: " + str(base) + " -- step: " + str(step)) y = base for i in range(0, step): r.axis(side=2, at=y, labels=str(y), las=2) y += base # legend r.legend(1, max_value, legend_labels, pch=[i for i in range(pch_start, pch_index)]) r.dev_off()