Skip to main content

Built-in type set and Set operations

Python provides a built-in data type set for handling sets.


from matplotlib_venn import venn3

# Create set objects: {}, set()
A = {2, 4, 6, 8, 10, 12}
B = {3, 6, 9, 12, 15, 18}
C = {5, 10, 15, 20, 25}

# Draw Venn Diagram with matplotlib-venn
v = venn3([A, B, C], set_labels = ('Set A', 'Set B', 'Set C'), set_colors=('gray', 'gray', 'gray'))

Mathematical operations:
# Intersection: &, intersection() 
# A∩B
print(set.intersection(A, B))
# {12, 6}

# Custom the Venn Diagram
v.get_patch_by_id('110').set_color('red')
plt.show()


end

Comments