def venn(inp, names, title="venn", folder=''): """ Plots a venn diagram using the pyvenn package Args: ----- inp: list[set()] of sets of values (e.g. [(1,2,3,4),(2,3),(1,3,4,5)]) names: list[str] of the name of each leaf title: str the plot title folder: str of location where to save the plot, won't save if empty """ labels = pyvenn.get_labels(inp, fill=['number', 'logic']) if len(inp) == 2: fig, ax = pyvenn.venn2(labels, names=names) elif len(inp) == 3: fig, ax = pyvenn.venn3(labels, names=names) elif len(inp) == 4: fig, ax = pyvenn.venn4(labels, names=names) elif len(inp) == 5: fig, ax = pyvenn.venn5(labels, names=names) elif len(inp) == 6: fig, ax = pyvenn.venn6(labels, names=names) else: raise ValueError('need to be between 2 to 6') ax.set_title(title) if folder: fig.savefig(folder + title + '_venn.pdf') fig.show() plt.pause(0.1)
def generate_venn_diagram(nb_dim, files, names, sep, label): """Cette fonction fait l'appel du fichier venn.py (qui doit être présent dans le même dossier que generate_venn.py) pour générer les diagrammes de Venn. :param: nombre de dimensions présent dans le diagramme de Venn (1 < nb_dim <= 6) :param: files: liste des chemins d'accès aux fichiers contenant les résultats des modèles :param: names: liste des noms des modèles (doit être en adéquation avec la liste des modèles files) :param: sep: séparateur présent dans filename séparant les id-instance des label :label: label que l'on souhaite extraire """ if nb_dim < 2 or nb_dim > 6: print( 'Le diagramme de Venn ne peut être généré que pour un nombre de dimensions supérieur à un et inférieur ou égal à 6.' ) else: i = 0 models = [] while i < nb_dim: models.append( get_id_instances_title(files[i], sep=sep, label=label)) i += 1 labels = venn.get_labels(models) if nb_dim == 2: fig, ax = venn.venn2(labels, names=names) plt.show() elif nb_dim == 3: fig, ax = venn.venn3(labels, names=names) plt.show() elif nb_dim == 4: fig, ax = venn.venn4(labels, names=names) plt.show() elif nb_dim == 5: fig, ax = venn.venn5(labels, names=names) plt.show() elif nb_dim == 6: fig, ax = venn.venn6(labels, names=names) plt.show() else: print( 'Le diagramme de Venn ne peut être généré que pour un nombre de dimensions supérieur à un et inférieur ou égal à 6.' )
n34 = len(intersection(tp[ids[2]], tp[ids[3]])) n35 = len(intersection(tp[ids[2]], tp[ids[4]])) n45 = len(intersection(tp[ids[3]], tp[ids[4]])) area5 = len(tp[ids[4]]) area4 = len(tp[ids[3]]) area3 = len(tp[ids[2]]) area2 = len(tp[ids[1]]) area1 = len(tp[ids[0]]) venn_diag_list = [area1, area2, area3, area4, area5, n12, n13, n14, n15,n23, n24, n25, n34, n35, n45, n123, n124, n125, n134, n135, n145, n234, n235, n245, n345, n1234, n1235, n1245, n1345, n2345, n12345] print('Overlap list needed for VennDiagram in R') print(venn_diag_list) out1.write('\n\n## Overlap list needed for VennDiagram in R:\n\n%s' % venn_diag_list) if plot.lower() == 't' or plot.lower() == 'true': if n_comparing == 5: labels = venn.get_labels([tp[ids[0]], tp[ids[1]], tp[ids[2]], tp[ids[3]], tp[ids[4]]], fill = ['number']) fig, ax = venn.venn5(labels, names = ids) elif n_comparing == 4: labels = venn.get_labels([tp[ids[0]], tp[ids[1]], tp[ids[2]], tp[ids[3]]], fill = ['number']) fig, ax = venn.venn4(labels, names = ids) elif n_comparing == 3: labels = venn.get_labels([tp[ids[0]], tp[ids[1]], tp[ids[2]]], fill = ['number']) fig, ax = venn.venn3(labels, names = ids) elif n_comparing == 2: labels = venn.get_labels([tp[ids[0]], tp[ids[1]]], fill = ['number']) fig, ax = venn.venn2(labels, names = ids) filename = save+'_pred_compared.pdf' fig.savefig(filename)
# -*- coding: utf-8 -*- """ @author: tctianchi https://github.com/tctianchi/pyvenn """ import matplotlib.pyplot as plt import venn labels = venn.get_labels([range(10), range(5, 15)], fill=['number', 'logic']) fig, ax = venn.venn2(labels, names=['list 1', 'list 2']) fig.savefig('venn2.png', bbox_inches='tight') plt.close() labels = venn.get_labels( [range(10), range(5, 15), range(3, 8)], fill=['number', 'logic']) fig, ax = venn.venn3(labels, names=['list 1', 'list 2', 'list 3']) fig.savefig('venn3.png', bbox_inches='tight') plt.close() labels = venn.get_labels( [range(10), range(5, 15), range(3, 8), range(8, 17)], fill=['number', 'logic']) fig, ax = venn.venn4(labels, names=['list 1', 'list 2', 'list 3', 'list 4']) fig.savefig('venn4.png', bbox_inches='tight') plt.close() labels = venn.get_labels( [range(10), range(5, 15),
n25 = len(intersection(comp[ids[1]], comp[ids[4]])) n34 = len(intersection(comp[ids[2]], comp[ids[3]])) n35 = len(intersection(comp[ids[2]], comp[ids[4]])) n45 = len(intersection(comp[ids[3]], comp[ids[4]])) area5 = len(comp[ids[4]]) area4 = len(comp[ids[3]]) area3 = len(comp[ids[2]]) area2 = len(comp[ids[1]]) area1 = len(comp[ids[0]]) venn_diag_list = [area1, area2, area3, area4, area5, n12, n13, n14, n15,n23, n24, n25, n34, n35, n45, n123, n124, n125, n134, n135, n145, n234, n235, n245, n345, n1234, n1235, n1245, n1345, n2345, n12345] print('Overlap list needed for VennDiagram in R') print(venn_diag_list) #out1.write('\n\n## Overlap list needed for VennDiagram in R:\n\n%s' % venn_diag_list) if n_comparing == 5: labels = venn.get_labels([comp[ids[0]], comp[ids[1]], comp[ids[2]], comp[ids[3]], comp[ids[4]]], fill = ['number']) fig, ax = venn.venn5(labels, names = ids) elif n_comparing == 4: labels = venn.get_labels([comp[ids[0]], comp[ids[1]], comp[ids[2]], comp[ids[3]]], fill = ['number']) fig, ax = venn.venn4(labels, names = ids) elif n_comparing == 3: labels = venn.get_labels([comp[ids[0]], comp[ids[1]], comp[ids[2]]], fill = ['number']) fig, ax = venn.venn3(labels, names = ids) elif n_comparing == 2: labels = venn.get_labels([comp[ids[0]], comp[ids[1]]], fill = ['number']) fig, ax = venn.venn2(labels, names = ids) filename = save+'_pred_compared.pdf' fig.savefig(filename)
# coding: utf-8 # ipython notebook requires this # %matplotlib inline # python console requires this import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import venn labels = venn.get_labels([range(10), range(5, 15)], fill=['number', 'logic']) fig, ax = venn.venn2(labels, names=['list 1', 'list 2']) fig.savefig('venn2.png', bbox_inches='tight') plt.close() labels = venn.get_labels([range(10), range(5, 15), range(3, 8)], fill=['number', 'logic']) fig, ax = venn.venn3(labels, names=['list 1', 'list 2', 'list 3']) fig.savefig('venn3.png', bbox_inches='tight') plt.close() labels = venn.get_labels([range(10), range(5, 15), range(3, 8), range(8, 17)], fill=['number', 'logic']) fig, ax = venn.venn4(labels, names=['list 1', 'list 2', 'list 3', 'list 4']) fig.savefig('venn4.png', bbox_inches='tight') plt.close() labels = venn.get_labels([range(10), range(5, 15), range(3, 8), range(8, 17), range(10, 20)], fill=['number', 'logic']) fig, ax = venn.venn5(labels, names=['list 1', 'list 2', 'list 3', 'list 4', 'list 5']) fig.savefig('venn5.png', bbox_inches='tight') plt.close()
elif "full_model" in results_file: all_labels.append("Full model") for r_label in results: # print unique TP to this result tps = set(results[r_label]["all"]) & set(gold_pairs["all"]) for r_label2 in results: if r_label2 == r_label: continue tps = tps - set(results[r_label2]["all"]) print() print("unique to {}:".format(r_label)) print(len(tps)) print(tps) print() print(all_labels) # print(results) labels = venn.get_labels(all_pairs, fill=["number"]) if len(all_pairs) == 2: fig, ax = venn.venn2(labels, names=all_labels) elif len(all_pairs) == 3: fig, ax = venn.venn3(labels, names=all_labels) elif len(all_pairs) == 4: fig, ax = venn.venn4(labels, names=all_labels) elif len(all_pairs) == 5: fig, ax = venn.venn5(labels, names=all_labels) elif len(all_pairs) == 6: fig, ax = venn.venn6(labels, names=all_labels) fig.savefig("{}.png".format("_".join(all_labels)), bbox_inches="tight") plt.close()