code_book/venn.py
def venn2(labels, names=['A', 'B'], **options):
    """
    plots a 2-set Venn diagram

    @type labels: dict[str, str]
    @type names: list[str]
    @rtype: (Figure, AxesSubplot)

    input
      labels: a label dict where keys are identified via binary codes ('01', '10', '11'),
              hence a valid set could look like: {'01': 'text 1', '10': 'text 2', '11': 'text 3'}.
              unmentioned codes are considered as ''.
      names:  group names
      more:   colors, figsize, dpi, fontsize

    return
      pyplot Figure and AxesSubplot object
    """
    colors = options.get('colors', [default_colors[i] for i in range(2)])
    figsize = options.get('figsize', (9, 7))
    dpi = options.get('dpi', 96)
    fontsize = options.get('fontsize', 14)

    fig = plt.figure(0, figsize=figsize, dpi=dpi)
    ax = fig.add_subplot(111, aspect='equal')
    ax.set_axis_off()
    ax.set_ylim(bottom=0.0, top=0.7)
    ax.set_xlim(left=0.0, right=1.0)

    # body
    draw_ellipse(fig, ax, 0.375, 0.3, 0.5, 0.5, 0.0, colors[0])
    draw_ellipse(fig, ax, 0.625, 0.3, 0.5, 0.5, 0.0, colors[1])
    draw_text(fig, ax, 0.74, 0.30, labels.get('01', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.26, 0.30, labels.get('10', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.50, 0.30, labels.get('11', ''), fontsize=fontsize)

    # legend
    draw_text(fig, ax, 0.20, 0.56, names[0], colors[0], fontsize=fontsize, ha="right", va="bottom")
    draw_text(fig, ax, 0.80, 0.56, names[1], colors[1], fontsize=fontsize, ha="left", va="bottom")
    leg = ax.legend(names, loc='center left', bbox_to_anchor=(1.0, 0.5), fancybox=True)
    leg.get_frame().set_alpha(0.5)

    return fig, ax

    plots a 2-set Venn diagram

    @type labels: dict[str, str]
    @type names: list[str]
    @rtype: (Figure, AxesSubplot)

    input
      labels: a label dict where keys are identified via binary codes ('01', '10', '11'),
              hence a valid set could look like: {'01': 'text 1', '10': 'text 2', '11': 'text 3'}.
              unmentioned codes are considered as ''.
      names:  group names
      more:   colors, figsize, dpi, fontsize

    return
      pyplot Figure and AxesSubplot object
    
plots a 2-set Venn diagram
plots a 2 - set Venn diagram
def venn2(labels, names=['A', 'B'], **options):
    colors = options.get('colors', [default_colors[i] for i in range(2)])
    figsize = options.get('figsize', (9, 7))
    dpi = options.get('dpi', 96)
    fontsize = options.get('fontsize', 14)
    fig = plt.figure(0, figsize=figsize, dpi=dpi)
    ax = fig.add_subplot(111, aspect='equal')
    ax.set_axis_off()
    ax.set_ylim(bottom=0.0, top=0.7)
    ax.set_xlim(left=0.0, right=1.0)
    draw_ellipse(fig, ax, 0.375, 0.3, 0.5, 0.5, 0.0, colors[0])
    draw_ellipse(fig, ax, 0.625, 0.3, 0.5, 0.5, 0.0, colors[1])
    draw_text(fig, ax, 0.74, 0.30, labels.get('01', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.26, 0.30, labels.get('10', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.50, 0.30, labels.get('11', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.20, 0.56, names[0], colors[0], fontsize=fontsize, ha="right", va="bottom")
    draw_text(fig, ax, 0.80, 0.56, names[1], colors[1], fontsize=fontsize, ha="left", va="bottom")
    leg = ax.legend(names, loc='center left', bbox_to_anchor=(1.0, 0.5), fancybox=True)
    leg.get_frame().set_alpha(0.5)
    return fig, ax
def venn2 ( labels , names = [ 'A' , 'B' ] , ** options ) : colors = options . get ( 'colors' , [ default_colors [ i ] for i in range ( 2 ) ] ) figsize = options . get ( 'figsize' , ( 9 , 7 ) ) dpi = options . get ( 'dpi' , 96 ) fontsize = options . get ( 'fontsize' , 14 ) fig = plt . figure ( 0 , figsize = figsize , dpi = dpi ) ax = fig . add_subplot ( 111 , aspect = 'equal' ) ax . set_axis_off ( ) ax . set_ylim ( bottom = 0.0 , top = 0.7 ) ax . set_xlim ( left = 0.0 , right = 1.0 ) draw_ellipse ( fig , ax , 0.375 , 0.3 , 0.5 , 0.5 , 0.0 , colors [ 0 ] ) draw_ellipse ( fig , ax , 0.625 , 0.3 , 0.5 , 0.5 , 0.0 , colors [ 1 ] ) draw_text ( fig , ax , 0.74 , 0.30 , labels . get ( '01' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.26 , 0.30 , labels . get ( '10' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.50 , 0.30 , labels . get ( '11' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.20 , 0.56 , names [ 0 ] , colors [ 0 ] , fontsize = fontsize , ha = "right" , va = "bottom" ) draw_text ( fig , ax , 0.80 , 0.56 , names [ 1 ] , colors [ 1 ] , fontsize = fontsize , ha = "left" , va = "bottom" ) leg = ax . legend ( names , loc = 'center left' , bbox_to_anchor = ( 1.0 , 0.5 ) , fancybox = True ) leg . get_frame ( ) . set_alpha ( 0.5 ) return fig , ax
plots a 2-set Venn diagram
plots a 2 - set Venn diagram
"""
    plots a 2-set Venn diagram

    @type labels: dict[str, str]
    @type names: list[str]
    @rtype: (Figure, AxesSubplot)

    input
      labels: a label dict where keys are identified via binary codes ('01', '10', '11'),
              hence a valid set could look like: {'01': 'text 1', '10': 'text 2', '11': 'text 3'}.
              unmentioned codes are considered as ''.
      names:  group names
      more:   colors, figsize, dpi, fontsize

    return
      pyplot Figure and AxesSubplot object
    """ # body
 # legend

None
(Figure, AxesSubplot)
input
  labels: a label dict where keys are identified via binary codes ('01', '10', '11'),
          hence a valid set could look like: {'01': 'text 1', '10': 'text 2', '11': 'text 3'}.
          unmentioned codes are considered as ''.
  names:  group names
  more:   colors, figsize, dpi, fontsize

return
  pyplot Figure and AxesSubplot object
labels
None
names
None