matplotlib 的 matshow() 函数用于绘制矩阵
示例1
import matplotlib.pyplot as plt
import numpy as np
mat = np.arange(0, 100).reshape(10, 10)
plt.matshow(mat, cmap=plt.cm.Blues)
plt.show()
示例2:
import matplotlib.pyplot as plt
import numpy as np
mat = np.arange(0, 100).reshape(10, 10)
plt.matshow(mat, cmap=plt.cm.gray)
plt.show()
示例3:
import matplotlib.pyplot as plt
import numpy as np
mat = np.random.rand(10, 10)
plt.matshow(mat, cmap=plt.cm.gray)
plt.show()
示例4:
import matplotlib.pyplot as plt
import numpy as np
mat = np.array([[1,2]])
mat= np.repeat(np.tile(mat, 5), 5, axis=0)
plt.matshow(mat, cmap=plt.cm.Blues)
plt.show()
示例5:
import matplotlib.pyplot as plt
import numpy as np
mat = np.arange(1, 10).reshape(3, 3)
plt.matshow(mat, cmap=plt.cm.BrBG)
for i in range(mat.shape[0]):
for j in range(mat.shape[1]):
plt.text(x=j, y=i, s=mat[i, j])
plt.show()