【发布时间】:2016-05-24 13:48:00
【问题描述】:
对于这个矩阵,我有一个二分图(1 和 0)和双簇(行和列数组的数组)的邻接矩阵。如何使用matplotlib matshow为属于不同簇的邻接矩阵中的元素(只有1个)设置不同的颜色?
import numpy as np
import matplotlib.pyplot as plt
a_matrix = np.array([[0, 0, 1, 0, 1], [0, 0, 0, 1, 0], [0, 0, 1, 1, 1], [1, 1, 0, 0, 0], [0, 1, 0, 0 ,0]])
cluster_1 = np.array([[1, 2, 3], [3, 4, 5]])
cluster_2 = np.array([[4, 5], [1, 2]])
# plot matrix with one colour
plt.matshow(a_matrix, cmap='Greys', interpolation='nearest')
邻接矩阵、双聚类和二部图:
【问题讨论】:
标签: python numpy matrix matplotlib