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


Python matplotlib_venn.venn2函数代码示例

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


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

示例1: make_venn

def make_venn(direc,file1,file2,filename,text1,text2,color1,color2,color3):
    smallername = ""
    biggername = ""
    fileinput1 = direc + file1
    fileinput2 = direc + file2
    statinfo1 = os.stat(fileinput1)
    statinfo2 = os.stat(fileinput2)
    if statinfo1.st_size > statinfo2.st_size:
        smallerfile = open(fileinput2)
        biggerfile = open(fileinput1)
        smallername = text2
        biggername = text1
    else:
        smallerfile = open(fileinput1)
        biggerfile = open(fileinput2)
        smallername = text1
        biggername = text2
    overlap_info = peak_overlap(smallerfile, biggerfile)
    file1_nums = overlap_info[1] - overlap_info[0]
    file2_nums = overlap_info[2] - overlap_info[0]
    print file1_nums, file2_nums
    if biggername == text1:
        v= venn2(subsets = (file2_nums, file1_nums, overlap_info[0]), set_labels = (biggername, smallername))
    else:
        v= venn2(subsets = (file1_nums, file2_nums, overlap_info[0]), set_labels = (smallername, biggername))
    print file2_nums, file1_nums, overlap_info[0]
    v.get_patch_by_id('10').set_color(color1)
    v.get_patch_by_id('01').set_color(color2)
    v.get_patch_by_id('11').set_color(color3)
    v.get_patch_by_id('10').set_alpha(1.0)
    v.get_patch_by_id('01').set_alpha(1.0)
    v.get_patch_by_id('11').set_alpha(0.7)
    plt.title(filename)
    savefig(filename)
    plt.close()
开发者ID:asonnens,项目名称:crm_analysis,代码行数:35,代码来源:exploratory_data_analysis.py

示例2: plot_venn

def plot_venn(t1=None, t2=None, t3=None, ax=None, set_colors=('r', 'b', 'k')):
	"""input: 2 or 3 tuples: (list/set, name_to_display) """
	assert len(t1) == len(t2) == 2
	if t3:
		venn3( [set(t[0]) for t in [t1,t2,t3]], tuple( ['%s\n(%s)'%(t[1], len(set(t[0])) ) for t in [t1,t2,t3]]) , set_colors=set_colors, alpha=0.5,ax=ax)
	else:
		venn2( [set(t[0]) for t in [t1,t2]], tuple( ['%s\n(%s)'%(t[1], len(set(t[0])) ) for t in [t1,t2]]), set_colors=set_colors[0:2],alpha=0.5, ax=ax)
开发者ID:MaayanLab,项目名称:Zika-RNAseq-Pipeline,代码行数:7,代码来源:plots.py

示例3: compre_two

def compre_two(ans_file1, ans_file2):

    with open(ans_file1) as f:
        a = json.load(f)
    with open(ans_file2) as f:
        b = json.load(f)

    true_a = []
    wrong_a = []
    for ele in a:
        if ele['em']:
            true_a.append(ele['id'])
        if not ele['f1']:
            wrong_a.append(ele['id'])

    true_b = []
    wrong_b = []
    for ele in b:
        if not ele['f1']:
            wrong_b.append(ele['id'])
        if ele['em']:
            true_b.append(ele['id'])

    label_a = get_label(ans_file1)
    label_b = get_label(ans_file2)
    venn2([set(true_a), set(true_b)], set_labels=(label_a, label_b))

    diff = set(true_b).intersection(set(wrong_a))
    if len(diff) > 20:
        diff = list(diff)[:20]
    print('true in b, but wrong in a:')
    print(diff)
开发者ID:SerenaKhoo,项目名称:Match-LSTM,代码行数:32,代码来源:ans_compare.py

示例4: venn_pair

def venn_pair( set1, set2, mask):
    set_a = set([v.strip() for v in open( mask % ethnicity_code[set1]).readlines()])
    set_b = set([v.strip() for v in open( mask % ethnicity_code[set2]).readlines()])
    
    plt.cla()
    venn2((set_a, set_b), set_labels=(set1, set2))
    plt.savefig("%s_%s_%s.png" % (set1, set2, 'venn'+mask.split('%s')[1] ))
开发者ID:CSB-IG,项目名称:non-coding-NGS,代码行数:7,代码来源:paired_intra_linguistc_group.py

示例5: draw_venn_diag

def draw_venn_diag(venn_dataset, first_name, second_name, out_dir):
    """Draws Venn diagram comparing genes hit in each dataset.

    Parameters
    ----------
    venn_dataset    :   list of integers
        First element   :   Number of genes with hits in first dataset only
        Second element  :   Number of genes with hits in second dataset only
        Third element   :   Number of genes with hits in both datasets
    *_name  :   string
        Filename for first or second input hits file directory
    out_dir :   string
        Name for output directory

    Writes
    -------
    venn_diag.*.png :   png file
        Venn diagram image
    """
    venn2(subsets=(venn_dataset[0], venn_dataset[1], venn_dataset[2]), 
            set_labels = (first_name, second_name))
    
    plt.title('$C.$ $albicans$ genes with hits')
    plt.savefig(os.path.join(out_dir, 'venn_diag.%s_and_%s.png' % (first_name, second_name)))
    plt.close()
开发者ID:berman-lab,项目名称:transposon-pipeline,代码行数:25,代码来源:AnalyzeAssays.py

示例6: func_plot

    def func_plot( self, json_data, str_output_figure ):
        """
        Function that quickly plots a venn diagram of data in a json file.
        """
        
        str_title = json_data[ qp.c_STR_TITLE ] if qp.c_STR_TITLE in json_data else qp.c_STR_TITLE_DEFAULT
        ldict_data = json_data[ qp.c_STR_DATA ]

        # Two venn diagram mode
        if len( ldict_data ) == 2:
            # Plot venn diagram
            # Labels
            str_data_label_1 = ldict_data[ 0 ][ qp.c_STR_DATA_LABEL ] if qp.c_STR_DATA_LABEL in ldict_data[ 0 ] else None
            str_data_label_2 = ldict_data[ 1 ][ qp.c_STR_DATA_LABEL ] if qp.c_STR_DATA_LABEL in ldict_data[ 1 ] else None
            # Set colors
            str_data_color_1 = ldict_data[ 0 ][ qp.c_C_PLOT_COLOR ] if qp.c_C_PLOT_COLOR in ldict_data[ 0 ] else 'r'
            str_data_color_2 = ldict_data[ 1 ][ qp.c_C_PLOT_COLOR ] if qp.c_C_PLOT_COLOR in ldict_data[ 1 ] else 'g'
            venn2( [ set( ldict_data[ 0 ][ qp.c_STR_DATA ] ), set( ldict_data[ 1 ][ qp.c_STR_DATA ] ) ],
                set_labels = [ str_data_label_1, str_data_label_2 ], set_colors = [ str_data_color_1, str_data_color_2 ] )
        else:
            return False

        plt.title( str_title )
        plt.tight_layout()
        plt.savefig( str_output_figure )
        plt.close()
        
        return True
开发者ID:TimothyTickle,项目名称:quickplots,代码行数:28,代码来源:vennDiagram.py

示例7: venn_diagram

def venn_diagram(df1, df2, labels=['A', 'B'], save=False):
    from matplotlib_venn import venn2
    import pandas as pd

    try:
        labels = [s.strip('.txt') for s in labels]
    except:
        pass

    s1 = set(df1.index)
    s2 = set(df2.index)
    venn2([s1, s2], set_colors=['navy','lightblue'], set_labels=labels)

    if save:
        inter = [s for s in s1 & s2]
        s1_only = [s for s in s1 - s2]
        s2_only = [s for s in s2 - s1]
        merge = pd.merge(df1, df2, how='outer',
                         left_index=True, right_index=True)
        merge.loc[inter].to_csv('inter.txt',
                                sep='\t', index=True, header=True)
        merge.loc[s1_only].to_csv('s1_only.txt',
                                  sep='\t', index=True, header=True)
        merge.loc[s2_only].to_csv('s2_only.txt',
                                  sep='\t', index=True, header=True)
        plt.savefig(labels[0] + '_vs_' + labels[1] , dpi=100)
开发者ID:jduc,项目名称:pylvg,代码行数:26,代码来源:hts_rnaseq.py

示例8: draw_venn2

def draw_venn2(A, B, sets):
    venn = [0]*3
    venn[2] = len(sets["AB"])
    venn[0] = len(sets["A"]) - len(sets["AB"])
    venn[1] = len(sets["B"]) - len(sets["AB"])
    labelA = A + " (" + str(len(sets["A"])) + ")"
    labelB = B + " (" + str(len(sets["B"])) + ")"
    print venn
    venn2(subsets=venn, set_labels=(labelA, labelB))
    plt.show()
开发者ID:BD2KGenomics,项目名称:brca-pipeline,代码行数:10,代码来源:venn_diagram.py

示例9: venn

def venn(args):
    """
    %prog venn *.benchmark

    Display benchmark results as Venn diagram.
    """
    from matplotlib_venn import venn2

    p = OptionParser(venn.__doc__)
    opts, args, iopts = p.set_image_options(args, figsize="9x9")

    if len(args) < 1:
        sys.exit(not p.print_help())

    bcs = args
    fig = plt.figure(1, (iopts.w, iopts.h))
    root = fig.add_axes([0, 0, 1, 1])

    pad = .02
    ystart = 1
    ywidth = 1. / len(bcs)
    tags = ("Bowers", "YGOB", "Schnable")
    for bc, tag in zip(bcs, tags):
        fp = open(bc)
        data = []
        for row in fp:
            prog, pcounts, tcounts, shared = row.split()
            pcounts = int(pcounts)
            tcounts = int(tcounts)
            shared = int(shared)
            data.append((prog, pcounts, tcounts, shared))
        xstart = 0
        xwidth = 1. / len(data)
        for prog, pcounts, tcounts, shared in data:
            a, b, c = pcounts - shared, tcounts - shared, shared
            ax = fig.add_axes([xstart + pad, ystart - ywidth + pad,
                               xwidth - 2 * pad, ywidth - 2 * pad])
            venn2(subsets=(a, b, c), set_labels=(prog, tag), ax=ax)
            message = "Sn={0} Pu={1}".\
                format(percentage(shared, tcounts, precision=0, mode=-1),
                       percentage(shared, pcounts, precision=0, mode=-1))
            print >> sys.stderr, message
            ax.text(.5, .92, latex(message), ha="center", va="center",
                    transform=ax.transAxes, color='b')
            ax.set_axis_off()
            xstart += xwidth
        ystart -= ywidth

    panel_labels(root, ((.04, .96, "A"), (.04, .96 - ywidth, "B"),
                  (.04, .96 - 2 * ywidth, "C")))
    panel_labels(root, ((.5, .98, "A. thaliana duplicates"),
                        (.5, .98 - ywidth, "14 Yeast genomes"),
                        (.5, .98 - 2 * ywidth, "4 Grass genomes")))
    normalize_axes(root)
    savefig("venn.pdf", dpi=opts.dpi)
开发者ID:xuanblo,项目名称:jcvi,代码行数:55,代码来源:synfind.py

示例10: plot_two_set_venn_diagram

def plot_two_set_venn_diagram(Ab, aB, AB, set_labels=None):
    '''
    Plots a two-set venn diagram, A and B.
    
    Inputs:
        Ab: counts in set A but not in B.
        AB: counts in both set A and B (intersection).
        aB: counts in set B but not in A.
        set_labels: a list of length 2 for set A (index 0) and set B (index 1).
    '''
    venn2(subsets=(Ab, Ab, AB), set_labels=set_labels)
    plt.show()
开发者ID:jakeyeung,项目名称:alternative-splicing,代码行数:12,代码来源:plot_utils.py

示例11: venn_pair

def venn_pair( set1, set2, mask):
    set_a = set()
    for s in linguistic_groups[set1]:
        set_a.update([v.strip() for v in open( mask % ethnicity_code[s]).readlines()])
    set_b = set()
    for s in linguistic_groups[set2]:
        set_b.update([v.strip() for v in open( mask % ethnicity_code[s]).readlines()])

    plt.cla()
    venn2((set_a, set_b), set_labels=(set1, set2))
#    figure.set_size_inches(3,15.4)
#    figure.set_dpi(400)
    plt.savefig("%s_%s_%s.svg" % (set1, set2, 'venn'+mask.split('%s')[1] ))
开发者ID:CSB-IG,项目名称:non-coding-NGS,代码行数:13,代码来源:paired_linguistic_group_jaccard_indexes.py

示例12: main

def main(*fields):
    client = MongoClient()
    db = client['github']
    influences = db['influences']
    sets = map(lambda x: set([i[0] for i in influences.find_one(
        {'field': x})['ranks'][:25]]), fields)

    venn2(sets, fields)
    plt.savefig('images/' +
                fields[0] + '-' + fields[1] +
                '-venn2.png')

    print sets[0].intersection(sets[1])
开发者ID:floydwch,项目名称:the-most-influential-developers-on-github,代码行数:13,代码来源:task_draw_venn2.py

示例13: main

def main(epistasis_file):
    
    dict_epistasis = {} #list of list of sequences, where each item represents a label 

    with open(epistasis_file) as e:
        lines = e.readlines()
        for l in lines[1:]: #ignore header line
	    tokens = l.split(',')
	    #value consists of Starting Ratio, Ending Ratio, Epistasis, Ending Fitness, # of Mutations, list of InterSeqs, list of InterFits, list of InterRatios
	    if dict_epistasis.get((tokens[2], tokens[0])) is None:
                dict_epistasis[(tokens[0],tokens[2])] = [ float(tokens[1]), float(tokens[3]), float(tokens[5]), tokens[4], len(tokens[6::3]), tokens[6::3], tokens[7::3], tokens[8::3] ]

    neg_epistasis = [0] * 4 
    no_epistasis = [0] * 4
    pos_epistasis = [0] * 4 
    n_functional = [0] * 4
    n_should_be_functional = [0] * 4
    n_total = [0] * 4

    for i in xrange(2,6):
	ind = i-2
        neg_epistasis[ind] = sum([ 1 for key, value in dict_epistasis.items() if value[2] < -0.000005 and value[4] == i ])
        no_epistasis[ind] = sum([ 1 for key, value in dict_epistasis.items() if abs(value[2]) < 0.000005 and value[4] == i ])
        pos_epistasis[ind] = sum([ 1 for key, value in dict_epistasis.items() if value[2] > 0.000005 and value[4] == i ])
	n_functional[ind] = sum([ 1 for key, value in dict_epistasis.items() if value[3] == "CLEAVED" and value[4] == i ])
        n_should_be_functional[ind] = sum([ 1 for key, value in dict_epistasis.items() if all(v == "CLEAVED" for v in value[6]) and value[4] == i ])
	n_total[ind] = float(sum([ 1 for key, value in dict_epistasis.items() if value[4] == i]))

    seq_func = set([ key[1] for key,val in dict_epistasis.items() if val[3] == "CLEAVED" ])
    seq_pred_func = set([ key[1] for key,val in dict_epistasis.items() if all(v == "CLEAVED" for v in val[6]) ]) 
    fig, axarr = pconv.create_ax(1, 1, shx=True, shy=True)
    fig2, axarr2 = pconv.create_ax(1, 1)
    artists = []
    artists.extend(plot_epi(no_epistasis, n_total, axarr[0,0], "No", color="gray"))
    artists.extend(plot_epi(neg_epistasis, n_total, axarr[0,0], "Neg.", bottom=no_epistasis, color="white"))
    artists.extend(plot_epi(pos_epistasis, n_total, axarr[0,0], "Pos.", bottom=[no + neg for no, neg in zip(no_epistasis, neg_epistasis)], color="black"))
    n_func_frac = [ func/total for func, total in zip(n_functional, n_total) ]
    n_pred_frac = [ pred/total for pred, total in zip(n_should_be_functional, n_total) ]
    scatterplot.plot_series(axarr2[0,0], [(range(2,6),n_func_frac,"% Cleaved"),(range(2,6),n_pred_frac,"% Pred Cleaved")], "", "Number of Mutations", "Fraction of Total Cases", size=40, connect_dots=True, alpha=1.0)
    axarr2[0,0].set_ylim([0,4.0])
    fig_venn, axarr_venn = pconv.create_ax(1, 1)

    venn2([seq_func, seq_pred_func], set_labels = ["Cleaved", "Pred Cleaved"], ax=axarr_venn[0,0])

    lgd = axarr[0,0].legend(artists,["No","Neg.","Pos."], loc="center left", bbox_to_anchor=(1.05, 0.5), borderaxespad=0., prop={'size':9}, ncol=1, fancybox=True)


    pconv.save_fig(fig, epistasis_file, "plot", 3, 2.5, tight=False, size=9, extra_artists=lgd)
    pconv.save_fig(fig2, epistasis_file, "pred_v_cl", 5, 5, tight=True, size=10)
    pconv.save_fig(fig_venn, epistasis_file, "venn", 5, 5, tight=True, size=14)
开发者ID:arubenstein,项目名称:deep_seq,代码行数:50,代码来源:PlotEpistasisDist.py

示例14: plot_venn

def plot_venn(List_of_sets,
              Set_labels,
              Main = "I forgot to give this plot a name.",
              Out_File = "",
              Custom_overlap_numbers = []):
    """
        Given a list of sets, generate a venn diagram in Out_Dir.
        
        Arguments:
            List_of_sets (two or three only!)
            Set_labels: Label for each circle
            Main: Title of plot
            Out_File: Where should plot be saved? And what should the file be named?
                Parent directory expected to already exist...
                This will overwrite plots if they already exist
            Custom_overlap_numbers: optional. If you want to supply your own 3 overlap sets:
                [# in first, # in second, # in both]
    """
    if not os.path.isdir(os.path.dirname(Out_File)):
        raise ValueError(os.path.dirname(Out_File)+" <--- PATH DOESN'T EXIST")
    
    if len(Custom_overlap_numbers) != 0 and len(Custom_overlap_numbers) != 3:
        raise ValueError("Custom overlap only works for 2 circle venn diagrams at the moment...")
    
    if len(Custom_overlap_numbers) == 3:
        plt.figure()
        venn2(subsets={'10': Custom_overlap_numbers[0], '01': Custom_overlap_numbers[1], '11': Custom_overlap_numbers[2]}, set_labels = Set_labels)
        plt.title(Main)
        plt.savefig(Out_File)
        return
                
    if len(List_of_sets) == 2:
        if len(Set_labels) != 2:
            raise ValueError("Set_labels needs to be the same length as the number of sets...")
        # Default figure dimensions...
        plt.figure()
        venn2(List_of_sets,Set_labels)
        plt.title(Main)
        plt.savefig(Out_File)
        
    elif len(List_of_sets) == 3:
        if len(Set_labels) != 3:
            raise ValueError("Set_labels needs to be the same length as the number of sets...")
        # Default figure dimensions...
        plt.figure()
        venn3(List_of_sets,Set_labels)
        plt.title(Main)
        plt.savefig(Out_File)
    else:
        raise ValueError("List_of_sets needs to be of length 2 or 3.")   
开发者ID:radlinsky,项目名称:splicing,代码行数:50,代码来源:splicing_fun.py

示例15: test_pr_28

def test_pr_28():
    import matplotlib_venn as mv
    v = mv.venn3((1, 2, 3, 4, 5, 6, 7), subset_label_formatter = None)
    assert v.get_label_by_id('010').get_text() == '2'
    v = mv.venn3((1, 2, 3, 4, 5, 6, 7), subset_label_formatter = lambda x: 'Value: %+0.3f' % (x / 100.0))
    assert v.get_label_by_id('010').get_text() == 'Value: +0.020'
    v = mv.venn2((1, 2, 3), subset_label_formatter = None)
    assert v.get_label_by_id('01').get_text() == '2'
    v = mv.venn2((1, 2, 3), subset_label_formatter = lambda x: 'Value: %+0.3f' % (x / 100.0))
    assert v.get_label_by_id('01').get_text() == 'Value: +0.020'
    
    v = mv.venn3_unweighted((1, 2, 3, 4, 5, 6, 7), subset_label_formatter = lambda x: 'Value: %+0.3f' % (x / 100.0))
    assert v.get_label_by_id('010').get_text() == 'Value: +0.020'
    v = mv.venn2_unweighted((1, 2, 3), subset_label_formatter = lambda x: 'Value: %+0.3f' % (x / 100.0))
    assert v.get_label_by_id('01').get_text() == 'Value: +0.020'
开发者ID:konstantint,项目名称:matplotlib-venn,代码行数:15,代码来源:issues_test.py


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