graph - Visualize sparsity pattern with intensity using Matlab spy function -


matlab has function spy visualizing sparsity patterns of graph adjacency matrices.

unfortunately not display points taking account magnitude of values in matrix. uses single color same intensity display entries.

i wish display same spy plot points "color-coded" in heatmap indicate magnitude of entries. how can that?

if matrix not large try view image using imagesc(). (well use quite large matrices well, pixels become small.)

here example of 20 random points in 100x100 matrix, using colormap hot:

n = 100; n = 20;  x = randi(n,1,n); y = randi(n,1,n); z = randi(n,1,n);  data = sparse(x,y,z);  imagesc(data) axis square colormap('hot') 

this resulting image.

imagesc using colormap hot

this can compared plot using spy(data) markers bit larger.

reference figure using spy

if white background desired easy way achieve flip colormap:

figure imagesc(data) axis square cmap = flipud(colormap('hot')); colormap(cmap) 

imagesc using reversed colormap hot

hack solution redefining spy()

googling bit found thread @ matlab central:

spy color values?

there solution suggested redefines spy(). it's worth noting (further down in thread) solution can cause matlab crash larger matrices.