Esempio n. 1
0
    def display_distancetree(self,
                             report,
                             max_level=100,
                             frac=0.5,
                             max_branching=5):
        plans, distances = self.cover.compute_distances()
        D = dict(distances)['pathlength']
        plan2point2 = get_embedding_mds(plans, D, ndim=2)
        plan2point3 = get_embedding_mds(plans, D, ndim=3)
        plan_level = lambda x: G.node[x]['level']
        _, G = make_distancetree(D, plans, max_branching=max_branching)
        copy_nodes_attrs(self.cover.G, G)

        n = len(plans)
        subnodes = [
            x for x in G
            if G.node[x]['level'] <= max_level and G.node[x]['order'] <= frac *
            n
        ]
        Gsub = G.subgraph(subnodes)
        f = report.figure()
        with f.data_file('tree', MIME_PNG) as filename:
            draw_node_graph(filename,
                            Gsub,
                            plan2point2.__getitem__,
                            color_func=plan_level,
                            label_func=lambda x: G.node[x]['order'],
                            cmap='Set2')

        with f.plot('2D') as pylab:
            plot_2d_graph(pylab, Gsub, plan2point2.__getitem__, plan_level)

        with f.plot('3D') as pylab:
            plot_3d_graph(pylab, Gsub, plan2point3.__getitem__, plan_level)
Esempio n. 2
0
    def draw_embedding(self, report, plans, D):
        
        f = report.figure('distances')
        
        report.data('plans', plans)
        report.data('distance', D).display('scale').add_to(f)
        with f.plot('D_stats', caption='Distance') as pylab:
            pylab.hist(D.flat, 100)

        if len(plans) < 3:
            msg = 'Cannot draw embedding with only %d plans. ' % (len(plans))
            report.text('warn', msg)
            return

        edges2color = lambda n1, n2: edges_type_to_color(self.G, n1, n2)

        with report.subsection('embed2d') as r2d:
            f = r2d.figure('embedding')
            with f.plot('2D') as pylab:
                plan2point2 = get_embedding_mds(plans, D, ndim=2)
                plan2color = self.visibility
                plot_2d_graph(pylab, self.G, plan2point2.__getitem__, plan2color,
                              edges2color)

        with report.subsection('embed3d') as r3d:
            f = r3d.figure()
            with f.plot('3D') as pylab:
                plan2point3 = get_embedding_mds(plans, D, ndim=3)
                plan2color = self.visibility
                plot_3d_graph(pylab, self.G, plan2point3.__getitem__,
                              plan2color, edges2color)
    def display_distancetree(self, report, max_level=100, frac=0.5,
                             max_branching=5):
        plans, distances = self.cover.compute_distances()
        D = dict(distances)['pathlength']
        plan2point2 = get_embedding_mds(plans, D, ndim=2)
        plan2point3 = get_embedding_mds(plans, D, ndim=3)
        plan_level = lambda x: G.node[x]['level']
        _, G = make_distancetree(D, plans, max_branching=max_branching)
        copy_nodes_attrs(self.cover.G, G)

        n = len(plans)
        subnodes = [x for x in G if G.node[x]['level'] <= max_level
                                and G.node[x]['order'] <= frac * n]
        Gsub = G.subgraph(subnodes)
        f = report.figure()
        with f.data_file('tree', MIME_PNG) as filename:
            draw_node_graph(filename, Gsub,
                            plan2point2.__getitem__,
                    color_func=plan_level,
                    label_func=lambda x: G.node[x]['order'],
                    cmap='Set2')
            
        with f.plot('2D') as pylab:
            plot_2d_graph(pylab, Gsub, plan2point2.__getitem__, plan_level)

        with f.plot('3D') as pylab:
            plot_3d_graph(pylab, Gsub, plan2point3.__getitem__, plan_level)