Z = sch.dendrogram(Y, orientation='right')
axdendro.set_xticks([])
axdendro.set_yticks([])
axmatrix = fig.add_axes([0.3, 0.1, 0.6, 0.8])
index = Z['leaves']
D = D[(index), :]
D = D[:, (index)]
im = axmatrix.matshow(D, aspect='auto', origin='lower')
axmatrix.set_xticks([])
axmatrix.set_yticks([])
axcolor = fig.add_axes([0.91, 0.1, 0.02, 0.8])
pylab.colorbar(im, cax=axcolor)
fig.show()
fig.savefig('dendrogram.png')
Reordering matrix elements to reflect column and row clustering in naiive python