plot.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:pymake 作者: dtrckd 项目源码 文件源码
def draw_blocks(comm):
    #nx.draw(H,G.position,
    #        node_size=[G.population[v] for v in H],
    #        node_color=node_color,
    #        with_labels=False)
    blocks = comm.get('block_hist')
    ties = comm.get('block_ties')

    blocks = 2*blocks / np.linalg.norm(blocks)
    max_n = max(blocks)

    G = nx.Graph(nodesep=0.7)
    u_colors.reset()
    ind_color = np.arange(0, len(blocks)**2, 2) % len(u_colors.seq)
    #ind_color = np.diag(np.arange(len(blocks)**2).reshape([len(blocks)]*2)) % len(u_colors.seq)
    colors = np.array(u_colors.seq)[ind_color]

    # if sorted
    sorted_blocks, sorted_ind = zip(*sorted( zip(blocks, range(len(blocks))) , reverse=True))
    for l, s in enumerate(sorted_blocks):
        if s == 0:
            continue
        G.add_node(int(l), width=s, height=s, fillcolor=colors[l], style='filled')

    max_t = max(ties, key=lambda x:x[1])[1]
    if max_t > max_n:
        scale = np.exp(2) * float(max_n) / max_t

    for l, s in ties:
        i, j = l
        # if sorted
        i = sorted_ind.index(int(i))
        j = sorted_ind.index(int(j))
        G.add_edge(i, j, penwidth = s * scale)

    return write_dot(G, 'graph.dot')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号