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

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

项目:facade-segmentation    作者:jfemiani    | 项目源码 | 文件源码
def plot_facade_cuts(self):

        facade_sig = self.facade_edge_scores.sum(0)
        facade_cuts = find_facade_cuts(facade_sig, dilation_amount=self.facade_merge_amount)
        mu = np.mean(facade_sig)
        sigma = np.std(facade_sig)

        w = self.rectified.shape[1]
        pad=10

        gs1 = pl.GridSpec(5, 5)
        gs1.update(wspace=0.5, hspace=0.0)  # set the spacing between axes.

        pl.subplot(gs1[:3, :])
        pl.imshow(self.rectified)
        pl.vlines(facade_cuts, *pl.ylim(), lw=2, color='black')
        pl.axis('off')
        pl.xlim(-pad, w+pad)

        pl.subplot(gs1[3:, :], sharex=pl.gca())
        pl.fill_between(np.arange(w), 0, facade_sig, lw=0, color='red')
        pl.fill_between(np.arange(w), 0, np.clip(facade_sig, 0, mu+sigma), color='blue')
        pl.plot(np.arange(w), facade_sig, color='blue')

        pl.vlines(facade_cuts, facade_sig[facade_cuts], pl.xlim()[1], lw=2, color='black')
        pl.scatter(facade_cuts, facade_sig[facade_cuts])

        pl.axis('off')

        pl.hlines(mu, 0, w, linestyle='dashed', color='black')
        pl.text(0, mu, '$\mu$ ', ha='right')

        pl.hlines(mu + sigma, 0, w, linestyle='dashed', color='gray',)
        pl.text(0, mu + sigma, '$\mu+\sigma$ ', ha='right')
        pl.xlim(-pad, w+pad)
项目:livespin    作者:biocompibens    | 项目源码 | 文件源码
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)))
项目:tap    作者:mfouesneau    | 项目源码 | 文件源码
def plotMAP(x, ax=None, error=0.01, frac=[0.65,0.95, 0.975], usehpd=True,
            hist={'histtype':'step'}, vlines={}, fill={},
            optbins={'method':'freedman'}, *args, **kwargs):
    """ Plot the MAP of a given sample and add statistical info
    If not specified, binning is assumed from the error value or using
    mystats.optbins if available.
    if mystats module is not available, hpd keyword has no effect

    inputs:
        x   dataset
    keywords
        ax  axe object to use during plotting
        error   error to consider on the estimations
        frac    fractions of sample to highlight (def 65%, 95%, 97.5%)
        hpd if set, uses mystats.hpd to estimate the confidence intervals

        hist    keywords forwarded to hist command
        optbins keywords forwarded to mystats.optbins command
        vlines  keywords forwarded to vlines command
        fill    keywords forwarded to fill command
        """
    _x = np.ravel(x)
    if ax is None:
        ax = plt.gca()
    if not ('bins' in hist):
        bins = get_optbins(x, method=optbins['method'], ret='N')
        n, b, p = ax.hist(_x, bins=bins, *args, **hist)
    else:
        n, b, p = ax.hist(_x, *args, **hist)
    c = 0.5 * (b[:-1] + b[1:])
    # dc = 0.5 * (b[:-1] - b[1:])
    ind = n.argmax()
    _ylim = ax.get_ylim()
    if usehpd is True:
        _hpd = hpd(_x, 1 - 0.01)
        ax.vlines(_hpd, _ylim[0], _ylim[1], **vlines)
        for k in frac:
            nx = hpd(_x, 1. - k)
            ax.fill_between(nx, _ylim[0], _ylim[1], alpha=0.4 / float(len(frac)), zorder=-1, **fill)
    else:
        ax.vlines(c[ind], _ylim[0], _ylim[1], **vlines)
        cx = c[ n.argsort() ][::-1]
        cn = n[ n.argsort() ][::-1].cumsum()
        for k in frac:
            sx = cx[np.where(cn <= cn[-1] * float(k))]
            sx = [sx.min(), sx.max()]
            ax.fill_between(sx, _ylim[0], _ylim[1], alpha=0.4 / float(len(frac)), zorder=-1, **fill)
    theme(ax=ax)
    ax.set_xlabel(r'Values')
    ax.set_ylabel(r'Counts')