def plot_matrix(self):
""" Plot distance matrix and dendrogram using matplotlib.
Returns
-------
matplotlib figure
"""
# Compute and plot first dendrogram for all nodes.
fig = pylab.figure(figsize=(8, 8))
ax1 = fig.add_axes([0.09, 0.1, 0.2, 0.6])
Z1 = scipy.cluster.hierarchy.dendrogram(
self.linkage, orientation='left', labels=self.labels)
ax1.set_xticks([])
ax1.set_yticks([])
# Compute and plot second dendrogram.
ax2 = fig.add_axes([0.3, 0.71, 0.6, 0.2])
Z2 = scipy.cluster.hierarchy.dendrogram(self.linkage, labels=self.labels)
ax2.set_xticks([])
ax2.set_yticks([])
# Plot distance matrix.
axmatrix = fig.add_axes([0.3, 0.1, 0.6, 0.6])
idx1 = Z1['leaves']
idx2 = Z2['leaves']
D = self.mat.copy()
if isinstance(D, pd.DataFrame):
D = D.as_matrix()
D = D[idx1, :]
D = D[:, idx2]
im = axmatrix.matshow(
D, aspect='auto', origin='lower', cmap=pylab.cm.YlGnBu)
axmatrix.set_xticks([])
axmatrix.set_yticks([])
# Plot colorbar.
axcolor = fig.add_axes([0.91, 0.1, 0.02, 0.6])
pylab.colorbar(im, cax=axcolor)
module_logger.info(
'Use matplotlib.pyplot.show() to render figure.')
return fig
评论列表
文章目录