test.py 文件源码

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

项目:polo 作者: adrianveres 项目源码 文件源码
def make_figure():
    gs = gridspec.GridSpec(5, 1,
                       height_ratios=[3, 1, 2, 3, 1],
                       hspace=0)

    data, Z, D = get_random_data(100, 0)
    order = leaves_list(Z)


    runtime, opt_Z = run_polo(Z, D)
    opt_order = leaves_list(opt_Z)

    fig = plt.figure(figsize=(5,5))
    axd1 = fig.add_subplot(gs[0,0])
    axd1.set_title("Random numbers, clustered using Ward's criterion, default linear ordering.", fontsize=9)
    dendrogram(Z, ax=axd1, link_color_func=lambda k: 'k')
    axd1.set_xticklabels(data[order].reshape(-1))
    axd1.set_xticks([])
    axd1.set_yticks([])

    axh1 = fig.add_subplot(gs[1,0])
    axh1.matshow(data[order].reshape((1,-1)), aspect='auto', cmap='RdBu', vmin=0, vmax=10000)
    axh1.set_xticks([])
    axh1.set_yticks([])

    axd2 = fig.add_subplot(gs[3,0])
    axd2.set_title("The same hierarchical clustering, arranged for optimal linear ordering.", fontsize=9)
    dendrogram(opt_Z, ax=axd2, link_color_func=lambda k: 'k')
    axd2.set_xticklabels(data[opt_order].reshape(-1))
    axd2.set_xticks([])
    axd2.set_yticks([])

    axh2 = fig.add_subplot(gs[4,0])
    axh2.matshow(data[opt_order].reshape((1,-1)), aspect='auto', cmap='RdBu', vmin=0, vmax=10000)
    axh2.set_xticks([])
    axh2.set_yticks([])

    fig.savefig('data/demo.png', dpi=130)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号