logo4 Evolution is progress—                          
progress is creativity.        
vline

Set Operations

view blog view wiki view wiki view wiki

This page demonstrates fundamental set operatons and the corresponding Venn diagramms as reference. The resulting set is shown in red.

Union

A \cup B

def set_figure(fig):    
   from matplotlib_venn import venn2

   ax=fig.add_subplot(1,1,1)
   v = venn2((3, 3, 1),ax=ax)
   v.get_patch_by_id('10').set_alpha(1.0)
   v.get_patch_by_id('10').set_color('r')
   v.get_label_by_id('10').set_text('')
   v.get_label_by_id('A').set_text('Set "A"')

   v.get_patch_by_id('01').set_alpha(1.0)
   v.get_patch_by_id('01').set_color('r')
   v.get_label_by_id('01').set_text('')
   v.get_label_by_id('B').set_text('Set "B"')
   
   v.get_patch_by_id('11').set_alpha(1.0)
   v.get_patch_by_id('11').set_color('r')
   v.get_label_by_id('11').set_text('')
Set Union

Intersection

A \cap B

def set_figure(fig):    
   from matplotlib_venn import venn2

   ax=fig.add_subplot(1,1,1)
   v = venn2((3, 3, 1),ax=ax)
   v.get_patch_by_id('10').set_alpha(1.0)
   v.get_patch_by_id('10').set_color('b')
   v.get_label_by_id('10').set_text('')
   v.get_label_by_id('A').set_text('Set "A"')

   v.get_patch_by_id('01').set_alpha(1.0)
   v.get_patch_by_id('01').set_color('b')
   v.get_label_by_id('01').set_text('')
   v.get_label_by_id('B').set_text('Set "B"')
   
   v.get_patch_by_id('11').set_alpha(1.0)
   v.get_patch_by_id('11').set_color('r')
   v.get_label_by_id('11').set_text('')
Set Intersection

Difference

A \setminus B

def set_figure(fig):    
   from matplotlib_venn import venn2

   ax=fig.add_subplot(1,1,1)
   v = venn2((3, 3, 1),ax=ax)
   v.get_patch_by_id('10').set_alpha(1.0)
   v.get_patch_by_id('10').set_color('r')
   v.get_label_by_id('10').set_text('')
   v.get_label_by_id('A').set_text('Set "A"')

   v.get_patch_by_id('01').set_alpha(1.0)
   v.get_patch_by_id('01').set_color('b')
   v.get_label_by_id('01').set_text('')
   v.get_label_by_id('B').set_text('Set "B"')
   
   v.get_patch_by_id('11').set_alpha(1.0)
   v.get_patch_by_id('11').set_color('b')
   v.get_label_by_id('11').set_text('')
Difference

Symmetric difference

A \bigtriangleup B

def set_figure(fig):    
   from matplotlib_venn import venn2

   ax=fig.add_subplot(1,1,1)
   v = venn2((3, 3, 1),ax=ax)
   v.get_patch_by_id('10').set_alpha(1.0)
   v.get_patch_by_id('10').set_color('r')
   v.get_label_by_id('10').set_text('')
   v.get_label_by_id('A').set_text('Set "A"')

   v.get_patch_by_id('01').set_alpha(1.0)
   v.get_patch_by_id('01').set_color('r')
   v.get_label_by_id('01').set_text('')
   v.get_label_by_id('B').set_text('Set "B"')
   
   v.get_patch_by_id('11').set_alpha(1.0)
   v.get_patch_by_id('11').set_color('b')
   v.get_label_by_id('11').set_text('')
Symmetric Difference

Categories: Mathematics Systems Theory

 
   

(c) Mato Nagel, Weißwasser 2004-2013, Disclaimer