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

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

项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def drawSmoothCatalog(self, catalog, label=None, **kwargs):
        ax = plt.gca()
        ra,dec = catalog.ra_dec
        x, y = sphere2image(self.ra,self.dec,ra,dec)

        delta_x = self.radius/100.
        smoothing = 2*delta_x
        bins = numpy.arange(-self.radius, self.radius + 1.e-10, delta_x)
        h, xbins, ybins = numpy.histogram2d(x, y, bins=[bins, bins])
        blur = nd.filters.gaussian_filter(h.T, smoothing / delta_x)

        defaults = dict(cmap='gray_r',rasterized=True)
        kwargs = dict(defaults.items()+kwargs.items())

        xx,yy = np.meshgrid(xbins,ybins)
        im = drawProjImage(xx,yy,blur,coord='C',**kwargs)

        if label:
            plt.text(0.05, 0.95, label, fontsize=10, ha='left', va='top', 
                     color='k', transform=pylab.gca().transAxes,
                     bbox=dict(facecolor='white', alpha=1., edgecolor='none'))
项目:privcount    作者:privcount    | 项目源码 | 文件源码
def plot_bar_chart(page, datasets, dataset_labels, dataset_colors, x_group_labels, err=0, title=None, xlabel='Bins', ylabel='Counts'):
    assert len(datasets) == len(dataset_colors) == len(dataset_labels)
    for dataset in datasets:
        assert len(dataset) == len(datasets[0])
        assert len(dataset) == len(x_group_labels)

    num_x_groups = len(datasets[0])
    x_group_locations = pylab.arange(num_x_groups)
    width = 1.0 / float(len(datasets)+1)

    figure = pylab.figure()
    axis = figure.add_subplot(111)
    bars = []

    for i in xrange(len(datasets)):
        bar = axis.bar(x_group_locations + (width*i), datasets[i], width, yerr=err, color=dataset_colors[i], error_kw=dict(ecolor='pink', lw=3, capsize=6, capthick=3))
        bars.append(bar)

    if title is not None:
        axis.set_title(title)
    if ylabel is not None:
        axis.set_ylabel(ylabel)
    if xlabel is not None:
        axis.set_xlabel(xlabel)

    axis.set_xticks(x_group_locations + width*len(datasets)/2)
    x_tick_names = axis.set_xticklabels(x_group_labels)
    rot = 0 if num_x_groups == 1 else 15
    pylab.setp(x_tick_names, rotation=rot, fontsize=10)
    axis.set_xlim(-width, num_x_groups)
    y_tick_names = axis.get_yticklabels()
    pylab.setp(y_tick_names, rotation=0, fontsize=10)

    axis.legend([bar[0] for bar in bars], dataset_labels)
    page.savefig()
    pylab.close()
项目:dynamic-walking    作者:stephane-caron    | 项目源码 | 文件源码
def test_dT_max_impact(nmpc, sim, start=0.1, end=0.8, step=0.02, ymax=200,
                       sample_size=200):
    xvals = pylab.arange(start, end + step, step)
    f = nmpc.update_dT_max
    label = '$\\Delta t_\\mathsf{max}$ (s)'
    return test_dT_impact(
        xvals, f, nmpc, sim, start, end, step, ymax, sample_size, label)
项目:dynamic-walking    作者:stephane-caron    | 项目源码 | 文件源码
def test_dT_min_impact(nmpc, sim, start=0.002, end=0.2, step=0.002, ymin=200,
                       sample_size=20):
    xvals = pylab.arange(start, end + step, step)
    f = nmpc.update_dT_min
    label = '$\\Delta t_\\mathsf{min}$ (s)'
    return test_dT_impact(
        xvals, f, nmpc, sim, start, end, step, ymin, sample_size, label)
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def drawHessDiagram(self,catalog=None):
        ax = plt.gca()
        if not catalog: catalog = self.get_stars()

        r_peak = self.kernel.extension
        angsep = ugali.utils.projector.angsep(self.ra, self.dec, catalog.ra, catalog.dec)
        cut_inner = (angsep < r_peak)
        cut_annulus = (angsep > 0.5) & (angsep < 1.) # deg

        mmin, mmax = 16., 24.
        cmin, cmax = -0.5, 1.0
        mbins = np.linspace(mmin, mmax, 150)
        cbins = np.linspace(cmin, cmax, 150)

        color = catalog.color[cut_annulus]
        mag = catalog.mag[cut_annulus]

        h, xbins, ybins = numpy.histogram2d(color, mag, bins=[cbins,mbins])
        blur = nd.filters.gaussian_filter(h.T, 2)
        kwargs = dict(extent=[xbins.min(),xbins.max(),ybins.min(),ybins.max()],
                      cmap='gray_r', aspect='auto', origin='lower', 
                      rasterized=True, interpolation='none')
        ax.imshow(blur, **kwargs)

        pylab.scatter(catalog.color[cut_inner], catalog.mag[cut_inner], 
                      c='red', s=7, edgecolor='none')# label=r'$r < %.2f$ deg'%(r_peak))
        ugali.utils.plotting.drawIsochrone(self.isochrone, c='b', zorder=10)
        ax.set_xlim(-0.5, 1.)
        ax.set_ylim(24., 16.)
        plt.xlabel(r'$g - r$')
        plt.ylabel(r'$g$')
        plt.xticks([-0.5, 0., 0.5, 1.])
        plt.yticks(numpy.arange(mmax - 1., mmin - 1., -1.))

        radius_string = (r'${\rm r}<%.1f$ arcmin'%( 60 * r_peak))
        pylab.text(0.05, 0.95, radius_string, 
                   fontsize=10, ha='left', va='top', color='red', 
                   transform=pylab.gca().transAxes,
                   bbox=dict(facecolor='white', alpha=1., edgecolor='none'))
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def drawMembersCMD(self,data):
        ax = plt.gca()
        if isinstance(data,basestring):
            filename = data
            data = pyfits.open(filename)[1].data

        xmin, xmax = -0.25,0.25
        ymin, ymax = -0.25,0.25
        mmin, mmax = 16., 24.
        cmin, cmax = -0.5, 1.0
        mbins = np.linspace(mmin, mmax, 150)
        cbins = np.linspace(cmin, cmax, 150)

        mag_1 = data[self.config['catalog']['mag_1_field']]
        mag_2 = data[self.config['catalog']['mag_2_field']]

        x_prob, y_prob = sphere2image(self.ra, self.dec, data['RA'], data['DEC'])

        sel = (x_prob > xmin)&(x_prob < xmax) & (y_prob > ymin)&(y_prob < ymax)
        sel_prob = data['PROB'][sel] > 5.e-2
        index_sort = numpy.argsort(data['PROB'][sel][sel_prob])

        plt.scatter(data['COLOR'][sel][~sel_prob], mag_1[sel][~sel_prob],
              marker='o',s=2,c='0.75',edgecolor='none')
        sc = pylab.scatter(data['COLOR'][sel][sel_prob][index_sort], mag_1[sel][sel_prob][index_sort], 
                   c=data['PROB'][sel][sel_prob][index_sort], 
                   marker='o', s=10, edgecolor='none', cmap='jet', vmin=0., vmax=1) 
        pylab.xlim(cmin, cmax)
        pylab.ylim(mmax, mmin)
        pylab.xlabel(r'$g - r$')
        pylab.ylabel(r'$g$')
        #axes[1].yaxis.set_major_locator(MaxNLocator(prune='lower'))
        pylab.xticks([-0.5, 0., 0.5, 1.])
        pylab.yticks(numpy.arange(mmax - 1., mmin - 1., -1.))

        ugali.utils.plotting.drawIsochrone(self.isochrone, c='k', zorder=10)

        pylab.text(0.05, 0.95, r'$\Sigma p_{i} = %i$'%(data['PROB'].sum()),
                   fontsize=10, horizontalalignment='left', verticalalignment='top', color='k', transform=pylab.gca().transAxes,
                   bbox=dict(facecolor='white', alpha=1., edgecolor='none'))

        divider = make_axes_locatable(pylab.gca())
        ax_cb = divider.new_horizontal(size="7%", pad=0.1)
        plt.gcf().add_axes(ax_cb)
        pylab.colorbar(sc, cax=ax_cb, orientation='vertical', ticks=[0, 0.2, 0.4, 0.6, 0.8, 1.0], label='Membership Probability')
        ax_cb.yaxis.tick_right()
项目: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 draw_slices(hist, func=np.sum, **kwargs):
    """ Draw horizontal and vertical slices through histogram """
    from mpl_toolkits.axes_grid1 import make_axes_locatable
    kwargs.setdefault('ls','-')
    ax = plt.gca()

    data = hist

    # Slices
    vslice = func(data,axis=0)
    hslice = func(data,axis=1)

    npix = np.array(data.shape)
    #xlim,ylim = plt.array(zip([0,0],npix-1))
    xlim = ax.get_xlim()
    ylim = ax.get_ylim()
    #extent = ax.get_extent()
    #xlim =extent[:2]
    #ylim = extent[2:]

    # Bin centers
    xbin = np.linspace(xlim[0],xlim[1],len(vslice))#+0.5 
    ybin = np.linspace(ylim[0],ylim[1],len(hslice))#+0.5
    divider = make_axes_locatable(ax)

    #gh2 = pywcsgrid2.GridHelperSimple(wcs=self.header, axis_nums=[2, 1])
    hax = divider.append_axes("right", size=1.2, pad=0.05,sharey=ax,
                              axes_class=axes_divider.LocatableAxes)
    hax.axis["left"].toggle(label=False, ticklabels=False)
    #hax.plot(hslice, plt.arange(*ylim)+0.5,'-') # Bin center
    hax.plot(hslice, ybin, **kwargs) # Bin center
    hax.xaxis.set_major_locator(MaxNLocator(4,prune='both'))
    hax.set_ylim(*ylim)

    #gh1 = pywcsgrid2.GridHelperSimple(wcs=self.header, axis_nums=[0, 2])
    vax = divider.append_axes("top", size=1.2, pad=0.05, sharex=ax,
                              axes_class=axes_divider.LocatableAxes)
    vax.axis["bottom"].toggle(label=False, ticklabels=False)
    vax.plot(xbin, vslice, **kwargs) 
    vax.yaxis.set_major_locator(MaxNLocator(4,prune='lower'))
    vax.set_xlim(*xlim)

    return vax,hax