2017-09-14 155 views
1

我正在使用matplotlib-venn包在python中繪製維恩圖。這個軟件包很好地用於繪製兩到三組維恩圖。但是,當其中一組比其他組更大時,小圈中的計數可以接近或重疊。這是一個例子。Matplotlib帶有圖例的維恩圖

from collections import Counter 
import matplotlib.pyplot as plt 
from matplotlib_venn import venn2, venn3 

sets = Counter() 
sets['01'] = 3000 
sets['11'] = 3 
sets['10'] = 5 
setLabels = ['set1', 'set2'] 

plt.figure() 
ax = plt.gca() 
v = venn2(subsets = sets, set_labels = setLabels, ax = ax) 
plt.title('Venn Diagram') 
plt.show() 

enter image description here

什麼我希望做的是移動計數(在這種情況下,3000,3,和5)與符合這些圖中色彩的傳奇人物。不知道如何用matplotlib_venn來做到這一點。

回答

0

可以更換標籤爲空字符串的維恩圖,而是創建一個從維恩的補丁和相應的數個傳說如下:

from collections import Counter 
import matplotlib.pyplot as plt 
from matplotlib_venn import venn2, venn3 

sets = Counter() 
sets['01'] = 3000 
sets['11'] = 3 
sets['10'] = 5 
setLabels = ['set1', 'set2'] 

plt.figure() 
ax = plt.gca() 
v = venn2(subsets = sets, set_labels = setLabels, ax = ax) 

h, l = [],[] 
for i in sets: 
    # remove label by setting them to empty string: 
    v.get_label_by_id(i).set_text("") 
    # append patch to handles list 
    h.append(v.get_patch_by_id(i)) 
    # append count to labels list 
    l.append(sets[i]) 

#create legend from handles and labels  
ax.legend(handles=h, labels=l, title="counts") 

plt.title('Venn Diagram') 
plt.show() 

enter image description here