当前位置: 首页>>代码示例>>Python>>正文


Python mlab.frange函数代码示例

本文整理汇总了Python中matplotlib.mlab.frange函数的典型用法代码示例。如果您正苦于以下问题:Python frange函数的具体用法?Python frange怎么用?Python frange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了frange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot

 def plot(self, policy):
     rows = len(policy)
     cols = len(policy[0])
     
     X,Y = meshgrid(range(rows), range(cols))
     
     # U, V give the x and y components of the arrow vectors
     U = [[0]*cols for _ in range(rows)]
     V = [[0]*cols for _ in range(rows)]
     
     for row,r in enumerate(policy):
         for col,c in enumerate(r):
             a = c[0]
             if a == 'N':
                 U[row][col] = 0
                 V[row][col] = 1
             elif a == 'S':
                 U[row][col] = 0
                 V[row][col] = -1
             elif a == 'E':
                 U[row][col] = 1
                 V[row][col] = 0
             elif a == 'W':
                 U[row][col] = -1
                 V[row][col] = 0
             else:
                 raise ValueError
                 
     ax = self.fig.add_subplot(111)
     ax.quiver(X, Y, U, V, pivot='middle')
     ax.grid(linestyle='-')
     ax.set_xticks(frange(0.5, cols))
     ax.set_yticks(frange(0.5, rows))
     ax.set_xticklabels([])
     ax.set_yticklabels([])
     
     xmin, xmax, ymin, ymax = ax.axis()
     ax.axis([xmin-0.5, xmax-1, ymin-0.5, ymax-1])
     
     if self.world:
         #map = 
         cdict = {'blue': ((0.0, 0.2, 0.2),
                           (0.25, 1, 1),
                           (1.0, 0, 0)),
                           
                  'green': ((0.0, 0.2, 0.2),
                            (0.25, 1, 1),
                            (1.0, 1, 1)),
                            
                   'red': ((0.0, 0.2, 0.2),
                           (0.25, 1, 1),
                           (1.0, 0, 0)) }
         
         cmap = LinearSegmentedColormap('fudge', cdict)
         
         ax.imshow(self.world, cmap=cmap, interpolation='nearest')
开发者ID:okkhoy,项目名称:gabe-and-joh,代码行数:56,代码来源:graph.py

示例2: Draw

def Draw(func1, func2):
    # генирация точек графиков
    xlist = mlab.frange(a, b, 0.01)
    ylist = [func1(x) for x in xlist]
    ylist2 = [func2(x) for x in xlist]
    # Генирирум ось
    y0 = [0 for x in xlist]

    #############################################################
    max1Y = max(ylist)
    min1Y = min(ylist)
    max2Y = max(ylist2)
    min2Y = min(ylist2)
    minmaxarrayY = []
    minmaxarrayX = []
    for i in range(len(ylist)):
        if ((max1Y == ylist[i]) or (min1Y == ylist[i])):
            minmaxarrayY.append(ylist[i])
            minmaxarrayX.append(xlist[i])

    for i in range(len(ylist2)):
        if ((max2Y == ylist2[i]) or (min2Y == ylist2[i])):
            minmaxarrayY.append(ylist2[i])
            minmaxarrayX.append(xlist[i])

    ################################################################
    extremumX, extremumY = converter(korn, 0, 3, 4, func1)
    inflectionX, inflectionY = converter(korn1, 0, 3, 4, func1)
    kornsX, kornsY = converter(table, 1, 3, 4, func1)

    pylab.plot(extremumX, extremumY, 'go', label='extremum', color='red')
    pylab.plot(inflectionX, inflectionY, 'go', label='inflection point', color='yellow')
    pylab.plot(minmaxarrayX, minmaxarrayY, 'go', label='min/max', color='green')
    pylab.plot(kornsX, kornsY, 'go', label='Korn', color='black')

    pylab.plot(xlist, ylist, label='$sin(x)/x$')
    pylab.plot(xlist, y0, color='pink')
    pylab.plot(xlist, ylist2, label='$0.02*x* x - 4$', color='pink')
    pylab.legend()

    # Включаем рисование сетки
    pylab.grid(True)
    xlist1 = mlab.frange(float(table2[0][3]), float(table2[len(table2) - 1][3]), 0.01)
    pylab.fill_between(xlist1, [func1(x) for x in xlist1], [func2(x) for x in xlist1], color='green', alpha=0.25)
    # если мало разбиений, то переопереляем сетку под шаг
    if ((round((b - a) / h)) < 25):
        pylab.xticks([a + i * h for i in range(round((b - a) / h) + 1)])

    print()
    print()
    print("Минимумы и максимумы:")
    print("X", "Y", sep="\t")
    for i in range(len(minmaxarrayY)):
        print('{:3.5g}'.format(minmaxarrayX[i]), '{:3.5g}'.format(minmaxarrayY[i]), sep='\t\t')
    # Рисуем фогрму с графиком
    pylab.show()
开发者ID:medva1997,项目名称:bmstu_sem2,代码行数:56,代码来源:lab3.py

示例3: box_grid

def box_grid(xlimp, ylimp):
    """box_grid   generate list of points on edge of box

    list = box_grid([xmin xmax xnum], [ymin ymax ynum]) generates a
    list of points that correspond to a uniform grid at the end of the
    box defined by the corners [xmin ymin] and [xmax ymax].
    """

    sx10 = frange(xlimp[0], xlimp[1], float(xlimp[1]-xlimp[0])/xlimp[2])
    sy10 = frange(ylimp[0], ylimp[1], float(ylimp[1]-ylimp[0])/ylimp[2])

    sx1 = np.hstack((0, sx10, 0*sy10+sx10[0], sx10, 0*sy10+sx10[-1]))
    sx2 = np.hstack((0, 0*sx10+sy10[0], sy10, 0*sx10+sy10[-1], sy10))

    return np.transpose( np.vstack((sx1, sx2)) )
开发者ID:03013304Huangyiting,项目名称:python-control,代码行数:15,代码来源:phaseplot.py

示例4: showF

def showF():
    '''Utility function to show F distributions'''
    
    t = frange(0, 3, 0.01)
    d1s = [1,2,5,100]
    d2s = [1,1,2,100]
    
    for (d1,d2) in zip(d1s,d2s):
        plot(t, stats.f.pdf(t, d1, d2), label='F({0}/{1})'.format(d1,d2))
    plt.legend()
        
    plt.xlim(0,3)
    plt.xlabel('X')
    plt.ylabel('pdf(X)')
    plt.axis('tight')
    plt.legend()
        
    outDir = r'..\Images'
    outFile = 'dist_f.png'
    
    saveTo = os.path.join(outDir, outFile)
    plt.savefig(saveTo, dpi=200)
    
    print('OutDir: {0}'.format(outDir))
    print('Figure saved to {0}'.format(outFile))
    plt.show()
    plt.close()
开发者ID:fluxium,项目名称:statsintro,代码行数:27,代码来源:figs_DistContinuous_multi.py

示例5: showChi2

def showChi2():
    '''Utility function to show Chi2 distributions'''
    
    t = frange(0, 8, 0.05)
    Chi2Vals = [1,2,3,5]
    
    for chi2 in Chi2Vals:
        plt.plot(t, stats.chi2.pdf(t, chi2), label='k={0}'.format(chi2))
    plt.legend()
        
    plt.xlim(0,8)
    plt.xlabel('X')
    plt.ylabel('pdf(X)')
    plt.axis('tight')
    
    outDir = r'..\Images'
    outFile = 'dist_chi2.png'
    
    saveTo = os.path.join(outDir, outFile)
    plt.savefig(saveTo, dpi=200)
    
    print('OutDir: {0}'.format(outDir))
    print('Figure saved to {0}'.format(outFile))
    plt.show()
    plt.close()
开发者ID:fluxium,项目名称:statsintro,代码行数:25,代码来源:figs_DistContinuous_multi.py

示例6: showT

def showT():
    '''Utility function to show T distributions'''
    
    t = frange(-5, 5, 0.05)
    TVals = [1,5]
    
    normal = stats.norm.pdf(t)
    t1 = stats.t.pdf(t,1)
    t5 = stats.t.pdf(t,5)
    
    plt.plot(t,normal, '--',  label='normal')
    plt.plot(t, t1, label='df=1')
    plt.plot(t, t5, label='df=5')
    plt.legend()
        
    plt.xlim(-5,5)
    plt.xlabel('X')
    plt.ylabel('pdf(X)')
    plt.axis('tight')
    
    outDir = r'..\Images'
    outFile = 'dist_t.png'
    
    saveTo = os.path.join(outDir, outFile)
    plt.savefig(saveTo, dpi=200)
    
    print('OutDir: {0}'.format(outDir))
    print('Figure saved to {0}'.format(outFile))
    plt.show()
    plt.close()
开发者ID:fluxium,项目名称:statsintro,代码行数:30,代码来源:figs_DistContinuous_multi.py

示例7: showExp

def showExp():
    '''Utility function to show exponential distributions'''
    
    t = frange(0, 3, 0.01)
    lambdas = [0.5, 1, 1.5]
    
    for par in lambdas:
        plt.plot(t, stats.expon.pdf(t, 0, par), label='$\lambda={0:3.1f}$'.format(par))
    plt.legend()
        
    plt.xlim(0,3)
    plt.xlabel('X')
    plt.ylabel('pdf(X)')
    plt.axis('tight')
    plt.legend()
        
    outDir = r'..\Images'
    outFile = 'dist_exp.png'
    
    saveTo = os.path.join(outDir, outFile)
    plt.savefig(saveTo, dpi=200)
    
    print('OutDir: {0}'.format(outDir))
    print('Figure saved to {0}'.format(outFile))
    plt.show()
    plt.close()
开发者ID:fluxium,项目名称:statsintro,代码行数:26,代码来源:figs_DistContinuous_multi.py

示例8: shifted_normal

def shifted_normal():
    '''PDF, scatter plot, and histogram.'''
    # Generate the data
    # Plot a normal distribution: "Probability density functions"
    myMean = [0,0,0,-2]
    mySD2 = [0.2,1,5,0.5]
    t = frange(-5,5,0.02)
    sns.set_palette('husl', 4)
    for mu,sigma in zip(myMean, np.sqrt(mySD2)):
        y = stats.norm.pdf(t, mu, sigma)
        plt.plot(t,y, label='$\mu={0}, \; \t\sigma={1:3.1f}$'.format(mu,sigma))
    plt.legend()
    plt.xlim([-5,5])
    plt.title('Normal Distributions')
    outFile = 'Normal_Distribution_PDF.png'
    
    saveTo = os.path.join(outDir, outFile)
    plt.savefig(saveTo, dpi=200)
    
    print('OutDir: {0}'.format(outDir))
    print('Figure saved to {0}'.format(outFile))
    plt.show()
    
    # Generate random numbers with a normal distribution
    myMean = 0
    mySD = 3
    numData = 500
    data = stats.norm.rvs(myMean, mySD, size = numData)
    plt.scatter(np.arange(len(data)), data)
    plt.title('Normally distributed data')
    plt.xlim([0,500])
    plt.ylim([-10,10])
    plt.show()
    plt.close()
开发者ID:hendryliu,项目名称:statsintro,代码行数:34,代码来源:figs_DistributionNormal.py

示例9: Draw

def Draw(func1, func2):
    # генирация точек графика
    xlist = mlab.frange(a, b, 0.01)
    ylist = [func1(x) for x in xlist]
    ylist2 = [func2(x) for x in xlist]

    # Генирирум ось
    y0 = [0 for x in xlist]
    pylab.plot(xlist, ylist)
    #pylab.plot(xlist, y0, label='line1', color='blue')
    pylab.plot(xlist, ylist2, label='$sin(x)/x)$', color='red')
    pylab.legend()

    # Включаем рисование сетки
    pylab.grid(True)

    pylab.fill_between(xlist, ylist, ylist2, color='green', alpha=0.25)
    # если мало разбиений, то переопереляем сетку под шаг
    if ((round((b - a) / h)) < 25):
        pylab.xticks([a + i * h for i in range(round((b - a) / h) + 1)])
    # рисуем корни, промерка того что корень не содержит ошибок
    for i in range(1, len(table)):
        if (table[i][4] != ':-('):
            pylab.scatter(table[i][3], table[i][4])

    # Рисуем фогрму с графиком
    pylab.show()
开发者ID:medva1997,项目名称:bmstu_sem2,代码行数:27,代码来源:roots_search.py

示例10: __init__

 def __init__(self, name='drawSinus'):
     print name, 'started!\n'
     # Интервал изменения переменной по оси X
     self.xmin = -20.0
     self.xmax =  20.0
     # Шаг между точками
     self.dx = 0.01
     #Создадим список координат по оси X
     #на отрезке [-xmin; xmax], включая концы
     self.xlist = mlab.frange (self.xmin, self.xmax, self.dx)
开发者ID:MakSim345,项目名称:Python,代码行数:10,代码来源:drawSinus_2.py

示例11: skewness

def skewness(ax):
    '''Normal and skewed distribution'''
    
    t = frange(-6,10,0.1) # generate the desirded x-values
    normal = stats.norm.pdf(t,1,1.6)   
    chi2 = stats.chi2.pdf(t,3)
    
    ax.plot(t, normal, '--', label='normal')
    ax.plot(t, chi2, label='positive skew')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.legend()
开发者ID:Mistobaan,项目名称:statsintro,代码行数:12,代码来源:figs_Skewness.py

示例12: test

def test():
    min, max, dx = 0, 16, 0.01

    for d in containerDot:
        a = listA(d)
        b = listB(d)
        h = np.linalg.solve(a, b)
        h = list(h)
        xlist = mlab.frange(min, max, dx)
        ylist = [f(x) for x in xlist]
        yrlist = [g(x, h) for x in xlist]
        pylab.plot(xlist, yrlist)
        pylab.plot(xlist, ylist)
        pylab.show()
开发者ID:HigerSkill,项目名称:Algorithms,代码行数:14,代码来源:approximation.py

示例13: CheckElevation

def CheckElevation(vec):
    #print vec
    step = 1.0/len(vec)
    vec_after_polyfit = createElevationVectorAfterPolyfit(mlab.frange(0,1-step,step),vec)
    vec_diff =  np.diff(np.array(vec_after_polyfit))
    elChange = vec_after_polyfit[-1] - vec_after_polyfit[1];
    if (elChange > ELEVATION_THRESHOLD):
        #print 'DOWN'
        if (mlab.find(vec_diff >= 0).size > VECTOR_SIZE*ELEVATION_TREND_PRECENT):
            return elChange,HAND_DOWN
    elif (elChange < -ELEVATION_THRESHOLD):
        #print 'UP'
        if (mlab.find(vec_diff <= 0).size > VECTOR_SIZE*ELEVATION_TREND_PRECENT):
            return elChange,HAND_UP
    return 0,HAND_UNKWON
开发者ID:amiravni,项目名称:Magic-Platform,代码行数:15,代码来源:gem.py

示例14: kurtosis

def kurtosis(ax):
    ''' Distributions with different kurtosis'''
    
    # Generate the data
    t = frange(-3,3,0.1) # generate the desirded x-values
    platykurtic = stats.laplace.pdf(t)
    
    wigner = np.zeros(np.size(t))
    wignerIndex = np.abs(t) <= 1
    wigner[wignerIndex] = 2/np.pi * np.sqrt(1-t[wignerIndex]**2)
    
    ax.plot(t, platykurtic, label='kurtosis=3')
    ax.plot(t, wigner, '--', label='kurtosis=-1')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.legend()
开发者ID:Mistobaan,项目名称:statsintro,代码行数:16,代码来源:figs_Skewness.py

示例15: __call__

 def __call__ (self) :
     binner     = self.binner
     delta      = self.delta
     phase      = self.phase
     vmin, vmax = self.viewInterval
     wmin       = binner.value (vmin, False)
     wmax       = binner.value (vmax, False)
     if phase is not None :
         wmin -= (wmin % delta - phase)
     return \
         [ i for i in
             (   binner.index_f (v)
             for v in frange (wmin, wmax + 0.001 * delta, delta)
             )
         if vmin <= i <= vmax
         ]
开发者ID:Tapyr,项目名称:tapyr,代码行数:16,代码来源:Bin_Locator.py


注:本文中的matplotlib.mlab.frange函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。