• python 用 matplotlib 的 matshow() 函数绘制矩阵


    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()

     

  • 相关阅读:
    操作系统简介
    计算机基础
    Django之form
    CMDB资产采集
    Git
    User model
    多级评论
    个人主页
    media路径设置
    Web框架
  • 原文地址:https://www.cnblogs.com/shanger/p/13021491.html
Copyright © 2020-2023  润新知