Python pylab 模块,errorbar() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pylab.errorbar()

项目:fang    作者:rgrosse    | 项目源码 | 文件源码
def plot_objfn(pos_term_info, log_Z_info, color, zoom=False, label=None):
    assert np.all(pos_term_info.counts == log_Z_info.counts)
    exact = not hasattr(log_Z_info, 'lower')

    mean = pos_term_info.values - log_Z_info.mean
    if not exact:
        lower = pos_term_info.values - log_Z_info.upper
        upper = pos_term_info.values - log_Z_info.lower

    pylab.semilogx(pos_term_info.counts, mean, color=color, label=label)
    if not exact:
        pylab.errorbar(pos_term_info.counts, (lower+upper)/2., yerr=(upper-lower)/2., fmt='', ls='None', ecolor=color)
    if zoom:
        pylab.ylim(mean.max() - 50., mean.max() + 5.)
项目:fang    作者:rgrosse    | 项目源码 | 文件源码
def plot_results(self, results, xloc, color, ls, label):
        iter_counts = sorted(set([it for it, av in results.keys() if av == self.average]))
        sorted_results = [results[it, self.average] for it in iter_counts]

        avg = np.array([r.train_logprob() for r in sorted_results])
        if hasattr(r, 'train_logprob_interval'):
            lower = np.array([r.train_logprob_interval()[0] for r in sorted_results])
            upper = np.array([r.train_logprob_interval()[1] for r in sorted_results])

        if self.logscale:
            plot_cmd = pylab.semilogx
        else:
            plot_cmd = pylab.plot

        xloc = xloc[:len(avg)]

        lw = 2.

        if label not in self.labels:
            plot_cmd(xloc, avg, color=color, ls=ls, lw=lw, label=label)
        else:
            plot_cmd(xloc, avg, color=color, ls=ls, lw=lw)

        self.labels.add(label)

        pylab.xticks(fontsize='xx-large')
        pylab.yticks(fontsize='xx-large')

        try:
            pylab.errorbar(xloc, (lower+upper)/2., yerr=(upper-lower)/2., fmt='', ls='None', ecolor=color)
        except:
            pass
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def drawDensityProfile(self, catalog=None):

        rmax = 24. # arcmin
        bins = numpy.arange(0, rmax + 1.e-10, 2.)
        centers = 0.5 * (bins[1:] + bins[0:-1])
        area = numpy.pi * (bins[1:]**2 - bins[0:-1]**2)

        r_peak = self.kernel.extension 

        stars = self.get_stars()
        angsep = ugali.utils.projector.angsep(self.ra, self.dec, 
                                              stars.ra, stars.dec)

        angsep_arcmin = angsep * 60 # arcmin
        cut_iso = self.isochrone_selection(stars)
        h = numpy.histogram(angsep_arcmin[(angsep_arcmin < rmax) & cut_iso], bins=bins)[0]
        h_out = numpy.histogram(angsep_arcmin[(angsep_arcmin < rmax) & (~cut_iso)], bins=bins)[0]

        gals = self.get_galaxies()
        if len(gals):
            angsep_gal = ugali.utils.projector.angsep(self.ra, self.dec, 
                                              gals.ra, gals.dec)

            angsep_gal_arcmin = angsep_gal * 60 # arcmin
            cut_iso_gal = self.isochrone_selection(gals)
            h_gal = np.histogram(angsep_gal_arcmin[(angsep_gal_arcmin < rmax) & cut_iso_gal], bins=bins)[0]
            h_gal_out = np.histogram(angsep_gal_arcmin[(angsep_gal_arcmin < rmax) & (~cut_iso_gal)], bins=bins)[0]

        plt.plot(centers, h/area, c='red', label='Filtered Stars')
        plt.errorbar(centers, h/area, yerr=(numpy.sqrt(h) / area), ecolor='red', c='red')
        plt.scatter(centers, h/area, edgecolor='none', c='red', zorder=22)

        plt.plot(centers, h_out/area, c='gray', label='Unfiltered Stars')
        plt.errorbar(centers, h_out/area, yerr=(numpy.sqrt(h_out) / area), ecolor='gray', c='gray')
        plt.scatter(centers, h_out/area, edgecolor='none', c='gray', zorder=21)

        if len(gals):
            plt.plot(centers, h_gal/area, c='black', label='Filtered Galaxies')
            plt.errorbar(centers, h_gal/area, yerr=(numpy.sqrt(h_gal) / area), ecolor='black', c='black')
            plt.scatter(centers, h_gal/area, edgecolor='none', c='black', zorder=20)

        plt.xlabel('Angular Separation (arcmin)')
        plt.ylabel(r'Density (arcmin$^{-2}$)')
        plt.xlim(0., rmax)
        ymax = pylab.ylim()[1]
        #pylab.ylim(0, ymax)
        pylab.ylim(0, 12)
        pylab.legend(loc='upper right', frameon=False, fontsize=10)
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def drawKernelHist(ax, kernel):
    ext = kernel.extension
    theta = kernel.theta
    lon, lat = kernel.lon, kernel.lat
    xmin,xmax = -5*ext,5*ext
    ymin,ymax = -5*ext,5*ext,
    x = np.linspace(xmin,xmax,100)+kernel.lon
    y = np.linspace(ymin,ymax,100)+kernel.lat

    xx,yy = np.meshgrid(x,y)
    zz = kernel.pdf(xx,yy)
    im = ax.imshow(zz)#,extent=[xmin,xmax,ymin,ymax])
    hax,vax = draw_slices(ax,zz,color='k')

    mc_lon,mc_lat = kernel.sample(1e5)
    hist,xedges,yedges = np.histogram2d(mc_lon,mc_lat,bins=[len(x),len(y)],
                                        range=[[x.min(),x.max()],[y.min(),y.max()]])
    xbins,ybins = np.arange(hist.shape[0])+0.5,np.arange(hist.shape[1])+0.5

    vzz = zz.sum(axis=0)
    hzz = zz.sum(axis=1)
    vmc = hist.sum(axis=0)
    hmc = hist.sum(axis=1)

    vscale = vzz.max()/vmc.max()
    hscale = hzz.max()/hmc.max()

    kwargs = dict(marker='.',ls='',color='r')
    hax.errorbar(hmc*hscale, ybins, xerr=np.sqrt(hmc)*hscale,**kwargs)
    vax.errorbar(xbins, vmc*vscale,yerr=np.sqrt(vmc)*vscale,**kwargs) 

    ax.set_ylim(0,len(y))
    ax.set_xlim(0,len(x))

    #try: ax.cax.colorbar(im)
    #except: pylab.colorbar(im)

    #a0 = np.array([0.,0.])
    #a1 =kernel.a*np.array([np.sin(np.deg2rad(theta)),-np.cos(np.deg2rad(theta))])
    #ax.plot([a0[0],a1[0]],[a0[1],a1[1]],'-ob')
    # 
    #b0 = np.array([0.,0.])
    #b1 =kernel.b*np.array([np.cos(np.radians(theta)),np.sin(np.radians(theta))])
    #ax.plot([b0[0],b1[0]],[b0[1],b1[1]],'-or')    

    label_kwargs = dict(xy=(0.05,0.05),xycoords='axes fraction', xytext=(0, 0), 
                        textcoords='offset points',ha='left', va='bottom',size=10,
                        bbox={'boxstyle':"round",'fc':'1'}, zorder=10)
    norm = zz.sum() * (x[1]-x[0])**2
    ax.annotate("Sum = %.2f"%norm,**label_kwargs)

    #ax.set_xlabel(r'$\Delta$ LON (deg)')
    #ax.set_ylabel(r'$\Delta$ LAT (deg)')

###################################################