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


Python pylab.hist函数代码示例

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


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

示例1: plotHist

  def plotHist(self, parsList=None):
    """
      Plots distributions for a number of traces.

      Parameters
      ----------
      parsList : string or list of strings, optional,
          Refers to a parameter name or a list of parameter names.
          If None, all available parameters are plotted.
    """
    if not ic.check["matplotlib"]:
      PE.warn(PE.PyARequiredImport("To use 'plotHists', matplotlib has to be installed.", \
                                   solution="Install matplotlib."))
      return
    if isinstance(parsList, basestring):
      parsList = [parsList]
    tracesDic = {}
    if parsList is not None:
      for parm in parsList:
        self._parmCheck(parm)
        tracesDic[parm] = self[parm]
    else:
      # Use all available traces
      for parm in self.availableParameters():
        tracesDic[parm] = self[parm]

    cols, rows = self.__plotsizeHelper(len(tracesDic))

    for i,[pars,trace] in enumerate(tracesDic.items()):
      if len(parsList) > 1:
        plt.subplot(rows, cols, i+1)
      plt.hist(trace, label=pars + " hist")
      plt.legend()
开发者ID:dhomeier,项目名称:PyAstronomy,代码行数:33,代码来源:anaMCMCTraces.py

示例2: fit_plot

    def fit_plot(self, data, topn=0, bins=20):
        """ Create a plot. """
        from matplotlib import pylab as pl

        distros = self.get_topn(topn)

        xx = numpy.linspace(data.min(), data.max(), 300)

        table = []
        nparms = max(len(x.parms) for x in distros)
        tcolours = []
        for dd in distros:
            patch = pl.plot(xx, [dd.pdf(p) for p in xx], label='%10.2f%% %s' % (100.0*dd.rss/dd.dss, dd.name))
            row = ['', dd.name, '%10.2f%%' % (100.0*dd.rss/dd.dss,)] + ['%0.2f' % x for x in dd.parms]
            while len(row) < 3 + nparms:
                row.append('')
            table.append(row)
            tcolours.append([patch[0].get_markerfacecolor()] + ['w'] * (2+nparms))

        # add a historgram with the data
        pl.hist(data, bins=bins, normed=True)
        tab = pl.table(cellText=table, cellColours=tcolours,
                       colLabels=['', 'Distribution', 'Res. SS/Data SS'] + ['P%d' % (x + 1,) for x in range(nparms)],
                       bbox=(0.0, 1.0, 1.0, 0.3))
                 #loc='top'))
        #pl.legend(loc=0)
        tab.auto_set_font_size(False)
        tab.set_fontsize(10.)
开发者ID:BackupGGCode,项目名称:pywafo,代码行数:28,代码来源:twolumps.py

示例3: summary

    def summary(self, file_idx=0, show_plot=False):

        print "Cluster output"
        s = self.cluster_membership.sum(0)
        nnz = (s>0).sum()
        
        print "Number of non-empty clusters: " + str(nnz) + " (of " + str(s.size) + ")"
        si = (self.cluster_membership).sum(0)
        print
        
        print "Size: count"
        for i in np.arange(0,si.max()+1):
            print str(i) + ": " + str((si==i).sum())
        t = (self.peak_data.possible.multiply(self.cluster_membership)).data
        t -= 1
        print
        
        print "Trans: count"
        for i in np.arange(len(self.peak_data.transformations)):
            print self.peak_data.transformations[i].name + ": " + str((t==i).sum())
        
        if show_plot:
            plt.figure()
            x = []
            cx = self.cluster_model.Z.tocoo()    
            for i,j,v in itertools.izip(cx.row, cx.col, cx.data):
                x.append(v)       
            x = np.array(x) 
    #         x = x[~np.isnan(x)]    
            plt.hist(x, 20)
            plt.title('Precursor mass clustering -- Z for file ' + str(file_idx))
            plt.xlabel('Probabilities')
            plt.ylabel('Count')
            plt.show()
开发者ID:sdrogers,项目名称:metabolomics_tools,代码行数:34,代码来源:plotting.py

示例4: distance_to_purchase_histogram

def distance_to_purchase_histogram(purchases):
    distances = calculate_distance_to_purchase_histogram(purchases)
    log_distances = [np.log10(0.1+d) for d in distances if d is not None]
    plt.hist(log_distances, 60, alpha=0.5)
    plt.xlabel('$log_{10}$ ( distances in miles )')
    plt.title('Distances between purchase and billing address')
    return distances
开发者ID:dave31415,项目名称:mitch,代码行数:7,代码来源:plotting.py

示例5: icsd_progress

def icsd_progress():
    n = 60
    tasks = Task.objects.filter(project_set='icsd', entry__natoms__lte=n)

    data = tasks.values_list('entry__natoms', 'state')
    done = []
    failed = []
    idle = []
    running = []
    for task in data:
        if task[1] == 2:
            done.append(task[0])
        elif task[1] == 1:
            running.append(task[0])
        elif task[1] == 0:
            idle.append(task[0])
        elif task[1] == -1:
            failed.append(task[0])

    plt.hist([ done, running, failed, idle], histtype='barstacked',
            label=['done', 'running' ,'failed', 'waiting'],
            bins=n)#, cumulative=True)
    plt.legend(loc='best')

    plt.xlabel('# of atoms in primitive cell')
    plt.ylabel('# of entries')

    img = StringIO.StringIO()
    plt.savefig(img, dpi=75, bbox_inches='tight')
    data_uri = 'data:image/jpg;base64,'
    data_uri += img.getvalue().encode('base64').replace('\n', '')
    plt.close()
    return data_uri
开发者ID:PingjieTang,项目名称:qmpy,代码行数:33,代码来源:__init__.py

示例6: plot_fitted_model

    def plot_fitted_model(self, sample, data, fig=None, xmin=-1, xmax=12, npoints=1000, nbins=100, epsilon=0.25):
        """Plot fitted model"""

        # fetch group
        group = [i for i, item in enumerate(data.groups.items()) if sample in item[1]][0]

        # fetch data
        counts = data.counts_norm[sample].values.astype('float')
        counts[counts < 1] = epsilon
        counts = np.log(counts)

        # compute fitted model
        x = np.reshape(np.linspace(xmin, xmax, npoints), (-1, 1))
        xx = np.exp(x)
        loglik = _compute_loglik(xx, self.log_phi, self.log_mu, self.beta[self.z[group]])
        y = xx * np.exp(loglik) / self.nfeatures

        # plot
        fig = pl.figure() if fig is None else fig
        pl.figure(fig.number)

        pl.hist(counts, nbins, histtype='stepfilled', linewidth=0, normed=True, color='gray')
        pl.plot(x, np.sum(y, 1), 'r')

        pl.grid()
        pl.xlabel('log counts')
        pl.ylabel('density')
        pl.legend(['model', 'data'], loc=0)
        pl.tight_layout()
开发者ID:dvav,项目名称:dgeclust,代码行数:29,代码来源:nbinom.py

示例7: scaleTestMinFinding

def scaleTestMinFinding():
	xs = range(10)
	distances = []
	noise = 3.5
	n = 1000000
	for i in range(n):
		a = random()
		b = random()
		c = random()
		ys = [x*x*a + x*b + c + random() * noise for x in xs]
		
		#print a, b, c, polynomialFit(xs, ys)[::-1]
		minExp, unc = polynomialFindMinimum(xs, ys, returnErrors = True)
		minCalc = -b/(2.0*a)
		dist = (minCalc - minExp) / unc
		#print minCalc, minExp, unc, dist
		distances.append(dist)
		
	print 'mean: %f' % stats.mean(distances)
	print 'stdDev: %f' % stats.stdDev(distances)
	for sigma in [1, 2, 3]:
		print 'With %d sigma: %f%%' % (sigma, 100.0 * sum([int(abs(d) < sigma) for d in distances]) / n)
	
	pylab.hist(distances, bins = 50, range = (-5, 5))
	pylab.show()
开发者ID:NickStupich,项目名称:PythonDFT-Analysis,代码行数:25,代码来源:polyFitTest.py

示例8: main

def main():
    criticidad = {'sup': 0, 'med': 0, 'inf': 0}
    promedios = []
    for i in range(EXPERIMENTOS):
        tiempo = 0
        for j in range(CORRIDAS):
            # romper huevos + revolver huevos
            sup = np.random.uniform(2, 4)+np.random.exponential(4)  
            # sumo fin cocinar huevos
            sup += np.random.uniform(2, 4)  
            med = np.random.uniform(6, 12)  # hacer tostadas + tostadas con matequilla
            inf = np.random.uniform(6, 12)  # freir tocino
            valores = {'sup': sup , 'med': med, 'inf': inf}
            maximo = max(valores.values())
            k_maximo = kmaximo(valores, maximo)
            valores[k_maximo] += 1
            criticidad[k_maximo] += 1
            tiempo += valores[k_maximo]
        promedios.append(tiempo/CORRIDAS)
    desv = np.std(promedios)
    promedio = np.average(promedios)
    print "Valores: ", valores.values()
    print "Desvio %s " % desv
    print "Promedio %s" % promedio
    print "Intervalos de confianza %.2f <= u <= %.2f , con un 99%% de confianza" \
        % (promedio - 2.57 * desv, promedio + 2.57 * desv)
    for k, v in criticidad.iteritems():
        print "criticidad %s, %.2f %%" % (k, v*100.00/(CORRIDAS*EXPERIMENTOS))
    hist(promedios,6)
    show()
开发者ID:Pazitos10,项目名称:Modelos-y-simulacion,代码行数:30,代码来源:tp6.py

示例9: mood_hist

def mood_hist(index):
    n_bins = 10
    data1 = pd.read_csv('data/split_class/large_IGNORE_406_mood_+1.txt', sep=' ', header=None)
    data2 = pd.read_csv('data/split_class/large_IGNORE_406_mood_-1.txt', sep=' ', header=None)

    mood_sum1 = pd.Series([0] * data1.shape[0])
    mood_sum2 = pd.Series([0] * data2.shape[0])
    # for i in np.arange(1, 7):
    for i in np.arange(1, 6):
        print(i)
        mood_sum1 += data1[i]
        mood_sum2 += data2[i]

    col1 = data1[index] / mood_sum1
    col2 = data2[index] / mood_sum2
    print(col1, col2)
    print(col1.mean())
    # print(col1.describe())
    print(col2.mean())
    # print(col2.describe())
    plt.subplot(1, 2, 1)
    plt.hist(col1, n_bins, alpha=0.8, color='r', linewidth=1.5)
    # plt.xlim(0, 0.5)

    plt.ylabel("frequency")
    plt.subplot(1, 2, 2)
    plt.hist(col2, n_bins, alpha=0.8, color='b', linewidth=1.5)
    # plt.xlim(0, 0.5)
    # plt.ylabel("frequency")
    plt.show()
开发者ID:kayzhou,项目名称:character_analysis,代码行数:30,代码来源:paint.py

示例10: shopping_hist

def shopping_hist():
    n_bins = 100
    data1 = pd.read_csv('data/split_class/large_IGNORE_404_shopping_+1.txt', sep=' ', header=None)
    data2 = pd.read_csv('data/split_class/large_IGNORE_404_shopping_-1.txt', sep=' ', header=None)

    shopping1 = data1[2]
    shopping2 = data2[2]
    for i in np.arange(3, 17):
        shopping1 += data1[i]
        shopping2 += data2[i]

    col1 = shopping1 / data1[1]
    print(col1.describe())
    col2 = shopping2 / data2[1]
    print(col2.describe())

    plt.subplot(1, 2, 1)
    plt.hist(col1, n_bins, normed=True, stacked=True, alpha=0.8, color='r', linewidth=1.5)
    plt.xlim(0, 0.5)
    plt.ylabel("frequency")
    plt.subplot(1, 2, 2)
    plt.hist(col2, n_bins, normed=True, stacked=True, alpha=0.8, color='b', linewidth=1.5)
    plt.xlim(0, 0.5)
    plt.ylabel("frequency")

    # plt.hist(data1[1], n_bins, normed=1, alpha=0.6, color='b', cumulative=True)
    # plt.hist(data2[1], alpha=0.6, color='r')
    plt.show()
开发者ID:kayzhou,项目名称:character_analysis,代码行数:28,代码来源:paint.py

示例11: hist_extraversion

def hist_extraversion():
    '''
    外倾性分数的分布, 及其正态分布曲线
    :return:
    '''
    n_bins = 10
    data = pd.read_csv('data/regress_train_data.txt', sep=' ', header=None)
    ext = data[1]
    mu = ext.mean()
    sigma = ext.std()
    print(mu, sigma)
    fig = plt.figure(figsize=(10, 8))
    # --- for *.eps --- #
    fig.set_rasterized(True)
    # plt.title("The distribution of score on extraversion")
    plt.xlabel("$Score\ on\ extraversion$", fontsize=20)
    plt.ylabel("$Probability$", fontsize=20)
    plt.grid(True)
    plt.hist(ext, n_bins, normed=1, alpha=0.8, rwidth=0.85)
    x = np.linspace(0, 60, 100)
    y = mlab.normpdf(x, mu, sigma)
    plt.xlim(0, 60)
    plt.ylim(0, 0.055)
    plt.xticks(fontsize=20)
    plt.yticks(fontsize=20)
    plt.plot(x, y, 'r--')
    # plt.tight_layout()
    plt.savefig('figure/ext_dist.eps', dpi=300)
    plt.show()
开发者ID:kayzhou,项目名称:character_analysis,代码行数:29,代码来源:paint.py

示例12: hist_shortest_path

def hist_shortest_path(g, filename, show=0):

    g.delete_vertices(
        [i for i, degree in enumerate(g.degree()) if degree == 0])

    # print g.degree()
    shortest_paths = g.shortest_paths_dijkstra(mode='all')
    # print shortest_paths
    # ig.plot(g)
    plt.hist(
        np.hstack(shortest_paths),
        range=[0, 5],
        bins=5,
        rwidth=1.,
        align='left',
        normed=True,
    )
    plt.xlabel('Number of steps')
    plt.ylabel('Proportion')

    plt.title(
        'Number of steps to each member (mean: %.2f)'
        % np.mean(shortest_paths))
    if show:
        plt.show()
    else:
        plt.savefig(filename)
开发者ID:keldLundgaard,项目名称:ThousandNetwork_simulation,代码行数:27,代码来源:simulation_stat_plots.py

示例13: plot_age_distribution_over_time

def plot_age_distribution_over_time(g_states, filename=None):
    num_plots = len(g_states)
    fig = plt.gcf()

    max_cols = 5
    if int(np.ceil(np.sqrt(num_plots))) >= max_cols:
        cols = max_cols
    else:
        cols = int(np.ceil(np.sqrt(num_plots)))

    rows = int(np.ceil(num_plots/cols))

    fig.set_size_inches(14, 5*rows)

    for i, g in enumerate(g_states):

        plt.subplot(rows, int(np.ceil(num_plots/float(rows))), i+1)

        plt.hist(
            g.vs['age'],
            bins=27,
            range=[18, 45],
            normed=True,
            label='t: %i' % i,
        )
        plt.legend()

    if filename:
        plt.savefig(filename)
    fig.clf()
开发者ID:keldLundgaard,项目名称:ThousandNetwork_simulation,代码行数:30,代码来源:simulation_stat_plots.py

示例14: compareHist

def compareHist(data1, data2,_title,tag1='data1', tag2='data2'):
    pl.figure()
    pl.show()
    pl.hist(data1, normed=True, alpha=0.5, color='b')
    pl.hist(data2, normed=True, alpha=0.5, color='r')

    # Fit a normal distribution to the data:
    mu1, std1 = stats.norm.fit(data1)
    xmin, xmax = pl.xlim()
    x = np.linspace(xmin, xmax, 100)
    p = stats.norm.pdf(x, mu1, std1)
    pl.plot(x, p, 'k', linewidth=2, color='b')

    # Fit a normal distribution to the data:
    mu2, std2 = stats.norm.fit(data2)
    xmin, xmax = pl.xlim()
    x = np.linspace(xmin, xmax, 100)
    p = stats.norm.pdf(x, mu2, std2)
    pl.plot(x, p, 'k', linewidth=2, color='r')

    pl.title(_title)
    pl.savefig(data_DIR + '/'+ _title + '.png',bbox_inches='tight')

    pl.close()
    return
开发者ID:XiaoxiaoLiu,项目名称:morphology_analysis,代码行数:25,代码来源:visualizeData.py.bk.py

示例15: tst_for_dataset

 def tst_for_dataset(self, creator, filename):
   from dials.array_family import flex
   from dials.algorithms.shoebox import MaskCode
   print filename
   rlist = flex.reflection_table.from_pickle(filename)
   shoebox = rlist['shoebox']
   background = [sb.background.deep_copy() for sb in shoebox]
   success = creator(shoebox)
   assert(success.count(True) == len(success))
   diff = []
   for i in range(len(rlist)):
     mask = flex.bool([(m & MaskCode.Foreground) != 0 for m in shoebox[i].mask])
     px1 = background[i].select(mask)
     px2 = shoebox[i].background.select(mask)
     den = max([flex.mean(px1), 1.0])
     diff.append(flex.mean(px2 - px1) / den)
   diff = flex.double(diff)
   mv = flex.mean_and_variance(flex.double(diff))
   mean = mv.mean()
   sdev = mv.unweighted_sample_standard_deviation()
   try:
     assert(abs(mean) < 0.01)
   except Exception:
     print "Mean: %f, Sdev: %f", mean, sdev
     from matplotlib import pylab
     pylab.hist(diff)
     pylab.show()
     raise
开发者ID:biochem-fan,项目名称:dials,代码行数:28,代码来源:tst_creator.py


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