code_book/venn.py
def venn4(labels, names=['A', 'B', 'C', 'D'], **options):
    """
    plots a 4-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 ('0001', '0010', '0100', ...),
              hence a valid set could look like: {'0001': 'text 1', '0010': 'text 2', '0100': '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(4)])
    figsize = options.get('figsize', (12, 12))
    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=1.0)
    ax.set_xlim(left=0.0, right=1.0)

    # body
    draw_ellipse(fig, ax, 0.350, 0.400, 0.72, 0.45, 140.0, colors[0])
    draw_ellipse(fig, ax, 0.450, 0.500, 0.72, 0.45, 140.0, colors[1])
    draw_ellipse(fig, ax, 0.544, 0.500, 0.72, 0.45, 40.0, colors[2])
    draw_ellipse(fig, ax, 0.644, 0.400, 0.72, 0.45, 40.0, colors[3])
    draw_text(fig, ax, 0.85, 0.42, labels.get('0001', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.68, 0.72, labels.get('0010', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.77, 0.59, labels.get('0011', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.32, 0.72, labels.get('0100', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.71, 0.30, labels.get('0101', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.50, 0.66, labels.get('0110', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.65, 0.50, labels.get('0111', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.14, 0.42, labels.get('1000', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.50, 0.17, labels.get('1001', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.29, 0.30, labels.get('1010', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.39, 0.24, labels.get('1011', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.23, 0.59, labels.get('1100', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.61, 0.24, labels.get('1101', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.35, 0.50, labels.get('1110', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.50, 0.38, labels.get('1111', ''), fontsize=fontsize)

    # legend
    draw_text(fig, ax, 0.13, 0.18, names[0], colors[0], fontsize=fontsize, ha="right")
    draw_text(fig, ax, 0.18, 0.83, names[1], colors[1], fontsize=fontsize, ha="right", va="bottom")
    draw_text(fig, ax, 0.82, 0.83, names[2], colors[2], fontsize=fontsize, ha="left", va="bottom")
    draw_text(fig, ax, 0.87, 0.18, names[3], colors[3], fontsize=fontsize, ha="left", va="top")
    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 4-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 ('0001', '0010', '0100', ...),
              hence a valid set could look like: {'0001': 'text 1', '0010': 'text 2', '0100': 'text 3', ...}.
              unmentioned codes are considered as ''.
      names:  group names
      more:   colors, figsize, dpi, fontsize

    return
      pyplot Figure and AxesSubplot object
    
plots a 4-set Venn diagram
plots a 4 - set Venn diagram
def venn4(labels, names=['A', 'B', 'C', 'D'], **options):
    colors = options.get('colors', [default_colors[i] for i in range(4)])
    figsize = options.get('figsize', (12, 12))
    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=1.0)
    ax.set_xlim(left=0.0, right=1.0)
    draw_ellipse(fig, ax, 0.350, 0.400, 0.72, 0.45, 140.0, colors[0])
    draw_ellipse(fig, ax, 0.450, 0.500, 0.72, 0.45, 140.0, colors[1])
    draw_ellipse(fig, ax, 0.544, 0.500, 0.72, 0.45, 40.0, colors[2])
    draw_ellipse(fig, ax, 0.644, 0.400, 0.72, 0.45, 40.0, colors[3])
    draw_text(fig, ax, 0.85, 0.42, labels.get('0001', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.68, 0.72, labels.get('0010', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.77, 0.59, labels.get('0011', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.32, 0.72, labels.get('0100', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.71, 0.30, labels.get('0101', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.50, 0.66, labels.get('0110', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.65, 0.50, labels.get('0111', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.14, 0.42, labels.get('1000', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.50, 0.17, labels.get('1001', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.29, 0.30, labels.get('1010', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.39, 0.24, labels.get('1011', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.23, 0.59, labels.get('1100', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.61, 0.24, labels.get('1101', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.35, 0.50, labels.get('1110', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.50, 0.38, labels.get('1111', ''), fontsize=fontsize)
    draw_text(fig, ax, 0.13, 0.18, names[0], colors[0], fontsize=fontsize, ha="right")
    draw_text(fig, ax, 0.18, 0.83, names[1], colors[1], fontsize=fontsize, ha="right", va="bottom")
    draw_text(fig, ax, 0.82, 0.83, names[2], colors[2], fontsize=fontsize, ha="left", va="bottom")
    draw_text(fig, ax, 0.87, 0.18, names[3], colors[3], fontsize=fontsize, ha="left", va="top")
    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 venn4 ( labels , names = [ 'A' , 'B' , 'C' , 'D' ] , ** options ) : colors = options . get ( 'colors' , [ default_colors [ i ] for i in range ( 4 ) ] ) figsize = options . get ( 'figsize' , ( 12 , 12 ) ) 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 = 1.0 ) ax . set_xlim ( left = 0.0 , right = 1.0 ) draw_ellipse ( fig , ax , 0.350 , 0.400 , 0.72 , 0.45 , 140.0 , colors [ 0 ] ) draw_ellipse ( fig , ax , 0.450 , 0.500 , 0.72 , 0.45 , 140.0 , colors [ 1 ] ) draw_ellipse ( fig , ax , 0.544 , 0.500 , 0.72 , 0.45 , 40.0 , colors [ 2 ] ) draw_ellipse ( fig , ax , 0.644 , 0.400 , 0.72 , 0.45 , 40.0 , colors [ 3 ] ) draw_text ( fig , ax , 0.85 , 0.42 , labels . get ( '0001' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.68 , 0.72 , labels . get ( '0010' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.77 , 0.59 , labels . get ( '0011' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.32 , 0.72 , labels . get ( '0100' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.71 , 0.30 , labels . get ( '0101' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.50 , 0.66 , labels . get ( '0110' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.65 , 0.50 , labels . get ( '0111' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.14 , 0.42 , labels . get ( '1000' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.50 , 0.17 , labels . get ( '1001' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.29 , 0.30 , labels . get ( '1010' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.39 , 0.24 , labels . get ( '1011' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.23 , 0.59 , labels . get ( '1100' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.61 , 0.24 , labels . get ( '1101' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.35 , 0.50 , labels . get ( '1110' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.50 , 0.38 , labels . get ( '1111' , '' ) , fontsize = fontsize ) draw_text ( fig , ax , 0.13 , 0.18 , names [ 0 ] , colors [ 0 ] , fontsize = fontsize , ha = "right" ) draw_text ( fig , ax , 0.18 , 0.83 , names [ 1 ] , colors [ 1 ] , fontsize = fontsize , ha = "right" , va = "bottom" ) draw_text ( fig , ax , 0.82 , 0.83 , names [ 2 ] , colors [ 2 ] , fontsize = fontsize , ha = "left" , va = "bottom" ) draw_text ( fig , ax , 0.87 , 0.18 , names [ 3 ] , colors [ 3 ] , fontsize = fontsize , ha = "left" , va = "top" ) 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 4-set Venn diagram
plots a 4 - set Venn diagram
"""
    plots a 4-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 ('0001', '0010', '0100', ...),
              hence a valid set could look like: {'0001': 'text 1', '0010': 'text 2', '0100': '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 ('0001', '0010', '0100', ...),
          hence a valid set could look like: {'0001': 'text 1', '0010': 'text 2', '0100': '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