scipy equivalent for MATLAB spy

前端 未结 3 935
我寻月下人不归
我寻月下人不归 2020-12-15 09:35

I have been porting code for an isomap algorithm from MATLAB to Python. I am trying to visualize the sparsity pattern using the spy function.

MATLAB command:

3条回答
  •  误落风尘
    2020-12-15 10:09

    Maybe it's your version of matplotlib that makes trouble, as for me scipy.sparse and matplotlib.pylab work well together.

    See sample code below that produces the 'spy' plot attached.

    import matplotlib.pylab as plt
    import scipy.sparse as sps
    A = sps.rand(10000,10000, density=0.00001)
    M = sps.csr_matrix(A)
    plt.spy(M)
    plt.show()
    
    # Returns here '1.3.0'
    matplotlib.__version__
    

    This gives this plot: enter image description here

提交回复
热议问题