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


Python pylab.bar方法代码示例

本文整理汇总了Python中pylab.bar方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.bar方法的具体用法?Python pylab.bar怎么用?Python pylab.bar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pylab的用法示例。


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

示例1: plot_barchart

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def plot_barchart(self, data, labels, colors, xlabel, ylabel, xticks, legendloc=1):
        self.big_figure()

        index = np.arange(len(data[0][0]))
        bar_width = 0.25

        pylab.grid("on", axis='y')
        pylab.ylim([0.5, 1.0])

        for i in range(0, len(data)):
            rects = pylab.bar(bar_width / 2 + index + (i * bar_width), data[i][0], bar_width,
                              alpha=0.5, color=colors[i],
                              yerr=data[i][1],
                              error_kw={'ecolor': '0.3'},
                              label=labels[i])

        pylab.legend(loc=legendloc, prop={'size': 12})

        pylab.xlabel(xlabel)
        pylab.ylabel(ylabel)
        pylab.xticks(bar_width / 2 + index + ((bar_width * (len(data[0]) + 1)) / len(data[0])), xticks) 
开发者ID:tonybeltramelli,项目名称:Deep-Spying,代码行数:23,代码来源:View.py

示例2: i1RepeatNucleotides

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def i1RepeatNucleotides(data, label=''):
    merged_data = mergeWithIndelData(data)
    nt_mean_percs, nts = [], ['A','T','G','C']
    for nt in nts:
        nt_data  = merged_data.loc[merged_data['Repeat Nucleotide Left'] == nt]  
        nt_mean_percs.append((nt_data['I1_Rpt Left Reads - NonAmb']*100.0/nt_data['Total reads']).mean())
    PL.figure(figsize=(3,3))
    PL.bar(range(4),nt_mean_percs)
    for i in range(4):
        PL.text(i-0.25,nt_mean_percs[i]+0.8,'%.1f' % nt_mean_percs[i])
    PL.xticks(range(4),nts)
    PL.ylim((0,26))
    PL.xlabel('PAM distal nucleotide\nadjacent to the cut site')
    PL.ylabel('I1 repeated left nucleotide\nas percent of total mutated reads')
    PL.show(block=False)
    saveFig('i1_rtp_nt_%s' % label) 
开发者ID:felicityallen,项目名称:SelfTarget,代码行数:18,代码来源:plot_i1_summaries.py

示例3: plotMergedI1Repeats

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def plotMergedI1Repeats(all_result_outputs, label=''):
    merged_data = mergeSamples(all_result_outputs, ['I1_Rpt Left Reads - NonAmb','Total reads'], data_label='i1IndelData', merge_on=['Oligo Id','Repeat Nucleotide Left'])
    nt_mean_percs, nts = [], ['A','T','G','C']
    for nt in nts:
        nt_data  = merged_data.loc[merged_data['Repeat Nucleotide Left'] == nt]  
        nt_mean_percs.append((nt_data['I1_Rpt Left Reads - NonAmb Sum']*100.0/nt_data['Total reads Sum']).mean())
    PL.figure(figsize=(3,3))
    PL.bar(range(4),nt_mean_percs)
    for i in range(4):
        PL.text(i-0.25,nt_mean_percs[i]+0.8,'%.1f' % nt_mean_percs[i])
    PL.xticks(range(4),nts)
    PL.ylim((0,26))
    PL.xlabel('PAM distal nucleotide\nadjacent to the cut site')
    PL.ylabel('I1 repeated left nucleotide\nas percent of total mutated reads')
    PL.show(block=False)
    saveFig('i1_rtp_nt') 
开发者ID:felicityallen,项目名称:SelfTarget,代码行数:18,代码来源:plot_i1_summaries.py

示例4: hist_overflow

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def hist_overflow(val, val_max, **kwds):
    """ Make a histogram with an overflow bar above val_max """
    import pylab, numpy

    overflow = len(val[val>=val_max])
    pylab.hist(val[val<val_max], **kwds)

    if 'color' in kwds:
        color = kwds['color']
    else:
        color = None

    if overflow > 0:
        rect = pylab.bar(val_max+0.05, overflow, .5, color=color)[0]
        pylab.text(rect.get_x(),
                   1.10*rect.get_height(), '%s+' % val_max) 
开发者ID:gwastro,项目名称:pycbc,代码行数:18,代码来源:plot.py

示例5: spikes_diagram

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def spikes_diagram(ts, gids, name, path):
    """
    Function for making spike diagrams
    :param ts:   (list) times
    :param gids: (list) global IDs of neurons
    :param name: (str) name of brain part
    :param path: (str) path to save results
    :return: None
    """
    pylab.figure()
    color_marker = "."
    color_bar = "blue"
    color_edge = "black"
    ylabel = "Neuron ID"
    hist_binwidth = 5.0
    location = pylab.axes([0.1, 0.3, 0.85, 0.6])
    pylab.plot(ts, gids, color_marker)
    pylab.ylabel(ylabel)
    xlim = pylab.xlim()
    pylab.xticks([])
    pylab.axes([0.1, 0.1, 0.85, 0.17])
    t_bins = numpy.arange(numpy.amin(ts), numpy.amax(ts), hist_binwidth)
    n, bins = pylab.histogram(ts, bins=t_bins)
    num_neurons = len(numpy.unique(gids))
    heights = (1000 * n / (hist_binwidth * num_neurons))
    # FixMe t_bins[:-1] should work without cutting the end value
    pylab.bar(t_bins[:-1], heights, width=hist_binwidth, color=color_bar, edgecolor=color_edge)
    pylab.yticks([int(a) for a in numpy.linspace(0.0, int(max(heights) * 1.1) + 5, 4)])
    pylab.ylabel("Rate (Hz)")
    pylab.xlabel("Time (ms)")
    pylab.grid(True)
    pylab.axes(location)
    pylab.title(name)
    pylab.xlim(xlim)
    pylab.draw()
    pylab.savefig("{0}{1}.png".format(path, name), dpi=dpi_n, format='png')
    pylab.close() 
开发者ID:research-team,项目名称:NEUCOGAR,代码行数:39,代码来源:build_diagram.py

示例6: plotDominantBars

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def plotDominantBars(all_result_outputs, label=''):
    pie_labels = ['I1_Rpt Left Reads - NonAmb','Ambiguous Rpt Reads','I1_Rpt Right Reads - NonAmb','I1_NonRpt Reads']
    mci_merged_data = mergeSamples(all_result_outputs, [], data_label='i1IndelData')
    mci_merged_data['Equal MCI'] = (mci_merged_data['Most Common Indel']==mci_merged_data['Most Common Indel 2']) & (mci_merged_data['Most Common Indel']==mci_merged_data['Most Common Indel 3'])
    mci_merged_data['Is Dominant I1'] = (mci_merged_data['Equal MCI'] & (mci_merged_data['MCI Type'] == 'I1'))
    
    oligo_data =  pd.read_csv(getHighDataDir() + '/ST_June_2017/data/self_target_oligos_details_with_pam_details.csv',sep='\t')
    remove_under = lambda x: x.replace('_','')
    oligo_data['Oligo Id'] = oligo_data['ID'].apply(remove_under)
    merged_mci_data = pd.merge(mci_merged_data, oligo_data[['Oligo Id','Guide']], how='inner',on='Oligo Id')

    nt_perc_i1, cnt_labels = [], []
    nts = 'ATGC'
    for nt in nts:
        is_nt = lambda guide: (guide[-4] == nt)
        nt_data = merged_mci_data.loc[merged_mci_data['Guide'].apply(is_nt)]
        nt_perc_i1.append(sum(nt_data['Is Dominant I1'])*100.0/len(nt_data))
        cnt_labels.append('%d/%d' % (sum(nt_data['Is Dominant I1']),  len(nt_data)))
    
    PL.figure()
    PL.bar(range(4), nt_perc_i1, width=0.8)
    for i, cnt in enumerate(cnt_labels):
        PL.text(i-0.3,nt_perc_i1[i]+5.0,cnt)
    PL.xticks(range(4), [x for x in nts])
    PL.xlabel('Nucleotide on Left of cut-site')
    PL.ylabel('Percent gRNAs with single nucleotide insertion\nas most common indel in all 3 replicates')
    PL.show(block=False)
    saveFig('I1_bar_3_rep') 
开发者ID:felicityallen,项目名称:SelfTarget,代码行数:30,代码来源:plot_i1_summaries.py

示例7: singularplot

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def singularplot(word, modelname, vector, fname):
    xlocations = np.array(list(range(len(vector))))
    plot.clf()
    plot.bar(xlocations, vector)
    plot_title = word.split('_')[0].replace('::', ' ') + '\n' + modelname + u' model'
    plot.title(plot_title, fontproperties=font)
    plot.xlabel('Vector components')
    plot.ylabel('Components values')
    plot.savefig(root + 'data/images/singleplots/' + modelname + '_' + fname + '.png', dpi=150,
                 bbox_inches='tight')
    plot.close()
    plot.clf() 
开发者ID:akutuzov,项目名称:webvectors,代码行数:14,代码来源:plotting.py

示例8: fit

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def fit(self, error_rate=0.05, semilogy=False, Nfit=100,
            error_kwargs={"lw":1, "color":"black", "alpha":0.2},
            fit_kwargs={"lw":2, "color":"red"}):
        self.mus = []
        self.sigmas = []
        self.amplitudes = []
        self.fits = []

        pylab.figure(1)
        pylab.clf()
        pylab.bar(self.X, self.Y, width=0.85, ec="k")

        for x in range(Nfit):
            # 10% error on the data to add errors 
            self.E = [scipy.stats.norm.rvs(0, error_rate) for y in self.Y]
            #[scipy.stats.norm.rvs(0, self.std_data * error_rate) for x in range(self.N)]
            self.result = scipy.optimize.least_squares(self.func, 
                (self.guess_mean, self.guess_std, self.guess_amp))

            mu, sigma, amplitude = self.result['x']
            pylab.plot(self.X, amplitude * scipy.stats.norm.pdf(self.X, mu,sigma),
                **error_kwargs)
            self.sigmas.append(sigma)
            self.amplitudes.append(amplitude)
            self.mus.append(mu)


            self.fits.append(amplitude * scipy.stats.norm.pdf(self.X, mu,sigma))

        self.sigma = mean(self.sigmas)
        self.amplitude = mean(self.amplitudes)
        self.mu = mean(self.mus)


        pylab.plot(self.X, self.amplitude * scipy.stats.norm.pdf(self.X, self.mu, self.sigma), 
                   **fit_kwargs)
        if semilogy:
            pylab.semilogy() 
        pylab.grid()

        pylab.figure(2)
        pylab.clf()
        #pylab.bar(self.X, self.Y, width=0.85, ec="k", alpha=0.5)
        M = mean(self.fits, axis=0)
        S = pylab.std(self.fits, axis=0)
        pylab.fill_between(self.X, M-3*S, M+3*S, color="gray", alpha=0.5)
        pylab.fill_between(self.X, M-2*S, M+2*S, color="gray", alpha=0.5)
        pylab.fill_between(self.X, M-S, M+S, color="gray", alpha=0.5)
        #pylab.plot(self.X, M-S, color="k")
        #pylab.plot(self.X, M+S, color="k")
        pylab.plot(self.X, self.amplitude * scipy.stats.norm.pdf(self.X, self.mu, self.sigma), 
                   **fit_kwargs)
        pylab.grid()

        return self.mu, self.sigma, self.amplitude 
开发者ID:cokelaer,项目名称:fitter,代码行数:57,代码来源:histfit.py

示例9: plotD1

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def plotD1(all_result_outputs, label=''):
    mci_merged_data = mergeSamples(all_result_outputs, [], data_label='perOligoMCI')
    mci_merged_data['Equal MCI'] = (mci_merged_data['Most Common Indel']==mci_merged_data['Most Common Indel 2']) & (mci_merged_data['Most Common Indel']==mci_merged_data['Most Common Indel 3'])
    mci_common = mci_merged_data.loc[mci_merged_data['Equal MCI']]
    pie_vals, pie_labels = [], []
    dmci_data = mci_common.loc[(mci_common['MCI Type'] == 'D1')] #Note: type check discards equally most common indels

    spans_cutsite = lambda indel: tokFullIndel(indel)[2]['L'] < -1 and tokFullIndel(indel)[2]['R'] > 0
    for nt in 'ATGC':
        is_mh = lambda alt_seq: len(alt_seq) >= 2 and alt_seq == (len(alt_seq)*nt)
        num_repeat_nt = len(dmci_data.loc[dmci_data['Altered Sequence'].apply(is_mh) & dmci_data['Most Common Indel'].apply(spans_cutsite)])
        pie_vals.append(num_repeat_nt*100.0/len(dmci_data))
        print(num_repeat_nt)
        pie_labels.append('Removal of %s\nfrom %s|%s' % (nt,nt,nt))
    is_non_repeat = lambda seq: len(seq) < 2 or seq != (seq[0]*len(seq))
    num_non_repeat  = len(dmci_data.loc[dmci_data['Altered Sequence'].apply(is_non_repeat) | ~dmci_data['Most Common Indel'].apply(spans_cutsite)])
    pie_vals.append(num_non_repeat*100.0/len(dmci_data))
    print(num_non_repeat)
    pie_labels.append('Removal from non-repeat')
    PL.figure(figsize=(4,4))
    PL.pie(pie_vals, labels=pie_labels, autopct='%.1f', labeldistance=1.1, counterclock=False, colors=OLD_COLORS)
    PL.title('Size 1 deletions that are\n"most common" for their gRNA in all 3 replicates\n(%d gRNAs from %d total)' % (len(dmci_data), len(mci_merged_data)))
    PL.show(block=False)
    saveFig('pie_chart_D1')
    

    oligo_data =  pd.read_csv(getHighDataDir() + '/ST_June_2017/data/self_target_oligos_details_with_pam_details.csv',sep='\t')
    remove_under = lambda x: x.replace('_','')
    oligo_data['Oligo Id'] = oligo_data['ID'].apply(remove_under)
    merged_mci_data = pd.merge(mci_merged_data, oligo_data[['Oligo Id','Guide']], how='inner',on='Oligo Id')
    print(len(merged_mci_data))

    nt_dbl_perc_d1, cnt_labels = [], []
    is_d1 = lambda indel: (indel.split('_')[0] == 'D1')
    non_dbl_nt = lambda row: row['Guide'][-4] != row['Guide'][-3]    
    nts = 'ATGC'
    for nt in nts:
        double_nt = lambda row: row['Guide'][-4:-2] == (nt+nt)
        dbl_data = merged_mci_data.loc[merged_mci_data.apply(double_nt,axis=1)]
        num_dbl_d1 = sum(dbl_data['Most Common Indel'].apply(is_d1) & dbl_data['Equal MCI'] & (dbl_data['Oligo Id']!='Oligo28137')) #Oligo28137: Corner case where a guide has CT|T and loses the C
        nt_dbl_perc_d1.append(num_dbl_d1*100.0/len(dbl_data))
        cnt_labels.append('%d/%d' % (num_dbl_d1,len(dbl_data)))
        print(len(dbl_data))
    non_dbl_data = merged_mci_data.loc[merged_mci_data.apply(non_dbl_nt,axis=1)]
    print(len(non_dbl_data))
    num_non_dbl_d1 = sum(non_dbl_data['Most Common Indel'].apply(is_d1) & non_dbl_data['Equal MCI'])
    nt_dbl_perc_d1.append(num_non_dbl_d1*100.0/len(non_dbl_data))
    cnt_labels.append('%d/%d' % (num_non_dbl_d1,len(non_dbl_data)))
    
    PL.figure()
    PL.bar(range(5), nt_dbl_perc_d1, width=0.8)
    for i, cnt in enumerate(cnt_labels):
        PL.text(i-0.3,nt_dbl_perc_d1[i]+5.0,cnt)
    PL.xticks(range(5), ['%s' % x*2 for x in nts] + ['Other'])
    PL.ylim((0,40))
    PL.xlabel('Nucleotides on either side of cut site')
    PL.ylabel('Percent gRNAs with single nucleotide deletion\nas most common indel in all 3 replicates')
    PL.show(block=False)
    saveFig('D1_bar_3_rep') 
开发者ID:felicityallen,项目名称:SelfTarget,代码行数:61,代码来源:plot_pie_indel_summaries.py

示例10: plotBarSummary

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def plotBarSummary(all_result_outputs, label='', data_label='PieData', plot_label='bar_plots', stacked=False, combine_reps=False, colors=['C0','C1','C2','C3','C4','C5','C6','C7','C8'], legcol=1, figsize=(6,4), cell_line_order = []):
    summaries = [(x[0][data_label], x[1]) for x in all_result_outputs]
    mapping = {'BOB':'Human iPSC','E14TG2A':'Mouse ESC'}
    if combine_reps: 
        combined_summaries = []
        for cell_line in cell_line_order:
            cell_line_summaries = [x[0] for x in summaries if (parseSampleName(x[1])[0] == cell_line)]
            combined_summaries.append((avPieSummaries(cell_line_summaries),(cell_line if cell_line not in mapping else mapping[cell_line])))
        summaries = combined_summaries

    PL.figure(figsize=figsize)
    pie_labels = summaries[0][0][1]
    N, M = len(pie_labels), len(summaries)
    width = 0.8 if stacked else 0.8/N
    bottoms = np.array([0.0] * M)
    for i, pie_label in enumerate(pie_labels):
        bar_heights = [x[0][0][pie_label] for x in summaries]
        cell_lines = [parseSampleName(x[1])[0] for x in summaries]
        if combine_reps or len(cell_line_order)==0:
            bar_pos = [i*width*int(not stacked)+j for j in np.arange(M)]
        else:
            bar_pos, prev_cl, xticks, xlabels, ncl = [-1.1*width], cell_lines[0], [], [], 0
            for cl in cell_lines:
                if cl != prev_cl: 
                    bar_pos.append(bar_pos[-1] + width*1.5)
                    xticks.append((bar_pos[-1]+bar_pos[-ncl])*0.5)
                    xlabels.append(mapping[prev_cl] if prev_cl in mapping else prev_cl)
                    ncl = 0
                else: bar_pos.append(bar_pos[-1] + width*1.1)
                prev_cl = cl
                ncl += 1
            xticks.append((bar_pos[-1]+bar_pos[-2]-width*0.4)*0.5)
            xlabels.append(mapping[prev_cl] if prev_cl in mapping else prev_cl)
            bar_pos = bar_pos[1:]
        print(pie_label,bar_heights)
        PL.bar(bar_pos,bar_heights,width,bottom=bottoms, label=pie_label, color=colors[i])
        if stacked:
            bottoms += np.array(bar_heights)
    PL.legend(loc='center right', ncol=legcol)
    #PL.title(label)
    if combine_reps:
        PL.xticks([x + N/2*width*int(not stacked) for x in np.arange(M)], [x[1] for x in summaries], rotation='vertical')
    elif len(cell_line_order)==0:
        PL.xticks([x + N/2*width*int(not stacked) for x in np.arange(M)], ['%s' % (getSimpleName(x[1],include_dpi=True) if not combine_reps else x[1]) for x in summaries], rotation='vertical')
    else:
        PL.xticks(xticks, xlabels, rotation='vertical')
    PL.xlim((-1,M*1.6))
    PL.subplots_adjust(left=0.15,right=0.95,top=0.95, bottom=0.25)
    PL.ylabel('Percent Mutated Reads')
    PL.show(block=False) 
    saveFig(plot_label) 
开发者ID:felicityallen,项目名称:SelfTarget,代码行数:53,代码来源:plot.py

示例11: write_selections_html

# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import bar [as 别名]
def write_selections_html(self, n, i, k, ind, label, scores):
    outdir = os.path.join('results', self.name)
    selfile = os.path.join(outdir, 'selections-k%d.html' % k)

    (objid, RA, DEC) = label.split('_')

    # If this is the first selection, open for write
    # to clear out previous run.
    if i == 0:
      # Start up the HTML file
      fid = open(selfile, 'w')
      fid.write('<html><head><title>DEMUD: %s, k=%d</title></head>\n' % (self.name, k))
      fid.write('<body>\n')
      fid.write('<h1>DEMUD experiments on %s with k=%d</h1>\n' % (self.name, k))
      fid.write('%d (%g) items analyzed.<br>\n' % 
                (self.data.shape[1], self.data.shape[1]))
      fid.write('<ul>\n')
      fid.write('<li>Selections are presented in decreasing order of novelty.</li>\n')
      fid.write('<li>Cutouts (left) are RGB images generated from the DES DR1 archive.</li>\n')
      fid.write('<li>The bar plot shows the <font color="blue">observed</font> values compared to the <font color="red">expected (modeled)</font> values.  Discrepancies explain why the chosen object is considered novel.  Click to enlarge.</li>\n')
      fid.write('<li>Scores close to 0 (for items other than the first one) indicate an arbitrary choice; novelty has been exhausted.</li>\n')
      fid.write('</ul>\n\n')

      # If scores is empty, the (first) selection was pre-specified,
      # so there are no scores.  Output -1 for this item.
      if scores == []:
        score = 'N/A'
      else:
        score = '%f' % scores[ind]
    else:
      # Append to the HTML file
      fid = open(selfile, 'a')
      score = scores[ind]

    fid.write('<h2>Selection %d: %s, RA %s, DEC %s, score %s</h2>\n' % 
              (i, objid, RA, DEC, score))
    fid.write('<a href="selection-%d-cutout.png"><img title="[%d] %s" src="selection-%d-cutout.png" height=270></a>\n' %
                  (i, i, objid, i))
    figfile = 'sel-%d-k-%d-(%s).png' % (i, k, label)
    fid.write('<a href="%s"><img height=270 src="%s"></a>\n\n' % 
              (figfile, figfile))

    # Close the file
    fid.close() 
开发者ID:wkiri,项目名称:DEMUD,代码行数:46,代码来源:dataset_des.py


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