我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用pylab.bar()。
def Unittest_Kline(): """""" kline = Guider("600100", "") print(kline.getData(0).date, kline.getLastData().date) #kline.myprint() obv = kline.OBV() pl.figure pl.subplot(2,1,1) pl.plot(kline.getCloses()) pl.subplot(2,1,2) ma,m2,m3 = kline.MACD() pl.plot(ma) pl.plot(m2,'r') left = np.arange(0, len(m3)) pl.bar(left,m3) #pl.plot(obv, 'y') pl.show() #Unittest_Kstp() # #??????????? #----------------------------------------------------------------------
def plot_and_save(self, filename="snakemake_stats.png", outputdir="report"): import pylab # If the plot cannot be created (e.g. no valid stats), we create an empty # axes try: self.plot() except: pylab.bar([0],[0]) if outputdir is None: pylab.savefig(filename) else: pylab.savefig(outputdir + os.sep + filename)
def test_dT_impact(xvals, f, nmpc, sim, start=0.1, end=0.8, step=0.02, ymax=200, sample_size=100, label=None): """Used to generate Figure XX of the paper.""" c = raw_input("Did you remove iter/time caps in IPOPT settings? [y/N] ") if c.lower() not in ['y', 'yes']: print "Then go ahead and do it." return stats = [Statistics() for _ in xrange(len(xvals))] fails = [0. for _ in xrange(len(xvals))] pylab.ion() pylab.clf() for (i, dT) in enumerate(xvals): f(dT) for _ in xrange(sample_size): nmpc.on_tick(sim) if 'Solve' in nmpc.nlp.return_status: stats[i].add(nmpc.nlp.solve_time) else: # max CPU time exceeded, infeasible problem detected, ... fails[i] += 1. yvals = [1000 * ts.avg if ts.avg is not None else 0. for ts in stats] yerr = [1000 * ts.std if ts.std is not None else 0. for ts in stats] pylab.bar( xvals, yvals, width=step, yerr=yerr, color='y', capsize=5, align='center', error_kw={'capsize': 5, 'elinewidth': 5}) pylab.xlim(start - step / 2, end + step / 2) pylab.ylim(0, ymax) pylab.grid(True) if label is not None: pylab.xlabel(label, fontsize=24) pylab.ylabel('Comp. time (ms)', fontsize=20) pylab.tick_params(labelsize=16) pylab.twinx() yfails = [100. * fails[i] / sample_size for i in xrange(len(xvals))] pylab.plot(xvals, yfails, 'ro', markersize=12) pylab.plot(xvals, yfails, 'r--', linewidth=3) pylab.xlim(start - step / 2, end + step / 2) pylab.ylabel("Failure rate [%]", fontsize=20) pylab.tight_layout()
def bar(pl, x, y): pl.figure pl.bar(x,y) pl.show() pl.close()
def bar(self, *args, **kwargs): pl.bar(*args, **kwargs)
def feature_importance(rf, save_path=None): """Plots feature importance of sklearn RandomForest Parameters ---------- rf : RandomForestClassifier save_path : str """ importances = rf.feature_importances_ nb = len(importances) tree_imp = [tree.feature_importances_ for tree in rf.estimators_] # print "Print feature importance of rf with %d trees." % len(tree_imp) std = np.std(tree_imp, axis=0) / np.sqrt(len(tree_imp)) indices = np.argsort(importances)[::-1] # Print the feature ranking # print("Feature ranking:") # for f in range(nb): # print("%d. feature %d (%f)" % # (f + 1, indices[f], importances[indices[f]])) # Plot the feature importances of the forest pl.figure() pl.title("Feature importances") pl.bar(range(nb), importances[indices], color="r", yerr=std[indices], align="center") pl.xticks(range(nb), indices) pl.xlim([-1, nb]) if save_path is not None: pl.savefig(save_path) pl.close()
def barplot(self,direction,alpha=0.4): import pylab pnormalize = pylab.normalize(vmin=1,vmax=len(self.distribution[direction])) count = 0 # dx = 0.1/(2*len(self.distribution[direction])) for target,(edges,heights) in self.distribution[direction].items(): count += 1 lefts = edges[:-1] # + count*dx widths = (edges[1:] - edges[:-1]) # - count*dx RGB = pylab.cm.jet(pnormalize(count))[:3] pylab.bar(lefts,heights,width=widths, alpha=alpha, color=RGB, label="%s" % target)
def bootstrap(self, nBoot, nbins = 20): pops = np.zeros((nBoot, nbins)) #medianpop = [[] for i in data.cat] pylab.figure(figsize = (20,14)) for i in xrange(3): pylab.subplot(1,3,i+1) #if i ==0: #pylab.title("Bootstrap on medians", fontsize = 20.) pop = self.angles[(self.categories == i)]# & (self.GFP > 2000)] for index in xrange(nBoot): newpop = np.random.choice(pop, size=len(pop), replace=True) #medianpop[i].append(np.median(newpop)) newhist, binedges = np.histogram(newpop, bins = nbins) pops[index,:] = newhist/1./len(pop) #pylab.hist(medianpop[i], bins = nbins, label = "{2} median {0:.1f}, std {1:.1f}".format(np.median(medianpop[i]), np.std(medianpop[i]), data.cat[i]), color = data.colors[i], alpha =.2, normed = True) meanpop = np.sum(pops, axis = 0)/1./nBoot stdY = np.std(pops, axis = 0) print "width", binedges[1] - binedges[0] pylab.bar(binedges[:-1], meanpop, width = binedges[1] - binedges[0], label = "mean distribution", color = data.colors[i], alpha = 0.6) pylab.fill_between((binedges[:-1]+binedges[1:])/2., meanpop-stdY, meanpop+stdY, alpha = 0.3) pylab.legend() pylab.title(data.cat[i]) pylab.xlabel("Angle(degree)", fontsize = 15) pylab.ylim([-.01, 0.23]) pylab.savefig("/users/biocomp/frose/frose/Graphics/FINALRESULTS-diff-f3/distrib_nBootstrap{0}_bins{1}_GFPsup{2}_{3}.png".format(nBoot, nbins, 'all', randint(0,999)))
def _plotVirtualTime(accessList, archName, fgname, rd_bin_width = 250): """ Plot data access based on virtual time """ print "converting to num arrary for _plotVirtualTime" stt = time.time() x, y, id, ad, yd = _raListToVTimeNA(accessList) print ("Converting to num array takes %d seconds" % (time.time() - stt)) fig = pl.figure() ax = fig.add_subplot(211) ax.set_xlabel('Access sequence number (%s to %s)' % (id.split('T')[0], ad.split('T')[0]), fontsize = 9) ax.set_ylabel('Observation sequence number', fontsize = 9) ax.set_title('%s archive activity ' % (archName), fontsize=10) ax.tick_params(axis='both', which='major', labelsize=8) ax.tick_params(axis='both', which='minor', labelsize=6) ax.plot(x, y, color = 'b', marker = 'x', linestyle = '', label = 'access', markersize = 3) #legend = ax.legend(loc = 'upper left', shadow=True, prop={'size':7}) ax1 = fig.add_subplot(212) ax1.set_xlabel('Access sequence number (%s to %s)' % (id.split('T')[0], ad.split('T')[0]), fontsize = 9) ax1.set_ylabel('Reuse distance (in-between accesses)', fontsize = 9) ax1.tick_params(axis='both', which='major', labelsize=8) ax1.tick_params(axis='both', which='minor', labelsize=6) ax1.plot(x, yd, color = 'k', marker = '+', linestyle = '', label = 'reuse distance', markersize = 3) pl.tight_layout() fig.savefig(fgname) pl.close(fig) y1d = yd[~np.isnan(yd)] num_bin = (max(y1d) - min(y1d)) / rd_bin_width hist, bins = np.histogram(y1d, bins = num_bin) width = 0.7 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 fig1 = pl.figure() #fig1.suptitle('Histogram of data transfer rate from Pawsey to MIT', fontsize=14) ax2 = fig1.add_subplot(111) ax2.set_title('Reuse distance Histogram for %s' % archName, fontsize = 10) ax2.set_ylabel('Frequency', fontsize = 9) ax2.set_xlabel('Reuse distance (# of observation)', fontsize = 9) ax2.tick_params(axis='both', which='major', labelsize=8) ax2.tick_params(axis='both', which='minor', labelsize=6) pl.bar(center, hist, align='center', width=width) fileName, fileExtension = os.path.splitext(fgname) fig1.savefig('%s_rud_hist%s' % (fileName, fileExtension)) pl.close(fig1)