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)
评论列表
文章目录