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

猜你喜欢

转载自blog.csdn.net/Hero_Never_GIVE_UP/article/details/82895103
今日推荐