def plot_class(fignum, name, pclass, y_max):
    def splice(ds):
        return ds.splice(ds.pclass == pclass)
    train = splice(TitanicDataSet.get_train())
    test = splice(TitanicDataSet.get_test())
    families = construct_family_components(train, test)
    families = sorted(families, key=lambda f: len(f.nodes))
    families = list(f for f in families if not f.difficult_parent_child)

    frames = []
    for f in families:
        nuclear_families, extra_nodes, extra_edges = find_nuclear_families(f)
        for nf in nuclear_families:
            frames.append(FamilyFrame(nf.mother, nf.father, nf.children))
        for e in extra_edges:
            if e.definitive_spouse:
                a,b = e.a, e.b
                if a.a.sex == 0:
                    a,b = b,a
                frames.append(CoupleFrame(a,b))
    frames.sort(key=lambda f: (not isinstance(f,CoupleFrame), f.n_members))

    for f in frames:
        f.setup()
        f.scale(1.1)

    fp = FramePlacer(11, 0.5, [0.5, 0.2])
    fp.place_frames(frames)

    plt.figure(fignum)
    plt.clf()
    for m,c,ps in fp.collect_points():
        plt.plot(ps[::, 0], ps[::, 1], linestyle='None', marker=m, color=c, ms=9)

    lines = LineCollection(fp.collect_lines(),
                           colors='k',
                           linestyles='solid')
    plt.gca().add_collection(lines)
    plt.title(name + 'Class Families')
    def label(label, **kwds):
        plt.plot([-1,-1], [-1,-1], label=label, **kwds)
    label('Female', marker='D', linestyle='None', markerfacecolor='white', color='k')
    label('Male', marker='o', linestyle='None', markerfacecolor='white', color='k')
    label('Survived', marker='s', linestyle='None', markerfacecolor=(0,1,0), markeredgecolor='white')
    label('Died', marker='s', linestyle='None', markerfacecolor='r', markeredgecolor='white')
    label('Unkown', marker='s', linestyle='None', markerfacecolor='k', markeredgecolor='white')
    plt.legend(loc='upper left', numpoints=1, frameon=False, ncol=3)
    plt.xlim(0, 12)
    plt.ylim(-0.1, y_max)
    plt.xticks([])
    plt.yticks([])
    plt.draw()
    plt.show()
    plt.savefig('%d_class_families.png' % (pclass+1,), bbox_inches='tight', pad_inches=0.1)
def main():
    train = TitanicDataSet.get_train()
    test = TitanicDataSet.get_test()
    families = construct_family_components(train, test)

    acc = []
    i = 0
    for c in families:
        #if len(c.nodes) == 1:
        #    continue
        nuclear_families, extra_nodes, extra_edges = find_nuclear_families(c)
        c.tear_down()
        acc.append(Component(extra_nodes, extra_edges))

        if sum(len(c.nodes) for c in acc) > 40:
            display_graph(i, acc)
            i += 1
            acc = []

    if acc:
        display_graph(i, acc)
def main():
    train = TitanicDataSet.get_train()
    test = TitanicDataSet.get_test()
    families = construct_family_components(train, test)

    acc = []
    i = 0
    for c in families:
        #if len(c.nodes) == 1:
        #    continue
        nuclear_families, extra_nodes, extra_edges = find_nuclear_families(c)
        c.tear_down()
        acc.append(Component(extra_nodes, extra_edges))

        if sum(len(c.nodes) for c in acc) > 40:
            display_graph(i, acc)
            i += 1
            acc = []

    if acc:
        display_graph(i, acc)
def plot_class(fignum, name, pclass, y_max):
    def splice(ds):
        return ds.splice(ds.pclass == pclass)

    train = splice(TitanicDataSet.get_train())
    test = splice(TitanicDataSet.get_test())
    families = construct_family_components(train, test)
    families = sorted(families, key=lambda f: len(f.nodes))
    families = list(f for f in families if not f.difficult_parent_child)

    frames = []
    for f in families:
        nuclear_families, extra_nodes, extra_edges = find_nuclear_families(f)
        for nf in nuclear_families:
            frames.append(FamilyFrame(nf.mother, nf.father, nf.children))
        for e in extra_edges:
            if e.definitive_spouse:
                a, b = e.a, e.b
                if a.a.sex == 0:
                    a, b = b, a
                frames.append(CoupleFrame(a, b))
    frames.sort(key=lambda f: (not isinstance(f, CoupleFrame), f.n_members))

    for f in frames:
        f.setup()
        f.scale(1.1)

    fp = FramePlacer(11, 0.5, [0.5, 0.2])
    fp.place_frames(frames)

    plt.figure(fignum)
    plt.clf()
    for m, c, ps in fp.collect_points():
        plt.plot(ps[::, 0],
                 ps[::, 1],
                 linestyle='None',
                 marker=m,
                 color=c,
                 ms=9)

    lines = LineCollection(fp.collect_lines(), colors='k', linestyles='solid')
    plt.gca().add_collection(lines)
    plt.title(name + 'Class Families')

    def label(label, **kwds):
        plt.plot([-1, -1], [-1, -1], label=label, **kwds)

    label('Female',
          marker='D',
          linestyle='None',
          markerfacecolor='white',
          color='k')
    label('Male',
          marker='o',
          linestyle='None',
          markerfacecolor='white',
          color='k')
    label('Survived',
          marker='s',
          linestyle='None',
          markerfacecolor=(0, 1, 0),
          markeredgecolor='white')
    label('Died',
          marker='s',
          linestyle='None',
          markerfacecolor='r',
          markeredgecolor='white')
    label('Unkown',
          marker='s',
          linestyle='None',
          markerfacecolor='k',
          markeredgecolor='white')
    plt.legend(loc='upper left', numpoints=1, frameon=False, ncol=3)
    plt.xlim(0, 12)
    plt.ylim(-0.1, y_max)
    plt.xticks([])
    plt.yticks([])
    plt.draw()
    plt.show()
    plt.savefig('%d_class_families.png' % (pclass + 1, ),
                bbox_inches='tight',
                pad_inches=0.1)