1. 程式人生 > >matplotlib.pyplot.matshow 矩陣視覺化

matplotlib.pyplot.matshow 矩陣視覺化

這是一個繪製矩陣的函式。原文:“plot a matrix or an array as an image"

用matshow繪製矩陣的例子:

import matplotlib.pyplot as plt
import numpy as np


def samplemat(dims):
    """Make a matrix with all zeros and increasing elements on the diagonal"""
    aa = np.zeros(dims)
    for i in range(min(dims)):
        aa[i, i] = i
    return aa


# Display matrix
plt.matshow(samplemat((15, 15)))

plt.show()

效果圖:

../../_images/sphx_glr_matshow_001.png