Search code examples
pythonpandasvenn-diagram

Hide some of the labels from venn diagram


I plotted a venn diagram that I'd like to hide part of the labels but don't know how to.

Example data

Course1=['A','C','Q']
Course2=['B','E','F','H','K','Q','R','S','T','U','V','Z']
Course3=['C','E','G']
vd3=venn3([set(Course1),set(Course2),set(Course3)],
 set_labels=('Course1', 'Course2','Course3'),
 set_colors=('#c4e6ff', '#F4ACB7','#9D8189'), 
 alpha = 0.8)
venn3_circles([set(Course1), set(Course2),set(Course3)], linestyle='-.', linewidth=2, color='grey')
plt.show()

enter image description here

How to hide Course 1 blue part and Course 3 brown part labels (the number "1") as they have no intersection?


Solution

  • You use .get_label_by_id().set_text() to set the text of spefic part.

    vd3.get_label_by_id('100').set_text('')
    vd3.get_label_by_id('001').set_text('')
    

    enter image description here

    To know what's the id of each part, you could use the following snippet to check

    labels = ['100', '101', '110', '010', '001', '011', '111']
    for label in labels:
        vd3.get_label_by_id(label).set_text(label)