How to draw a matrix sparsity pattern with color code in python? -
i using spy matplotlib.pyplot draw sparsity pattern of csc_matrix scipy.sparse this
>>> import scipy.sparse sprs >>> import matplotlib.pyplot plt >>> matrix=sprs.rand(10,10, density=0.1, format='csc') >>> plt.spy(matrix) >>> plt.show()
i want same give colors matrix elements according magnitude. there simple way make spy this? if not, there way it?
you use imshow
:
d=matrix.todense() plt.imshow(d,interpolation='none',cmap='binary') plt.colorbar()
gives:
Comments
Post a Comment