Search code examples
matlabmatrixplotmatlab-figuredensity-plot

Density plot of a matrix


I have a 100x200 matrix and I would like to show this matrix as a density plot. Here is a 8x10 sample.

X = [104 122 138 159 149 167 184 164 190 158; ...
     54  42  55  55  63  75  72  73  66  76; ...
     15  22  28  21  23  28  32  47  32  40; ...
     18  12  20  22  28  17  30  17  22  18; ...
     10  7   14  10  14  11  14  20  16  10; ...
     5   6   3   3   6   12  6   2   8   9; ...
     4   8   9   2   5   3   3   12  7   7; ...
     6   6   2   3   10  1   9   8   11  8]

I have tried to use functions like bar3, surf, hist and so on but they don't have the end result I am after.

I would also like to represent the y axis on the new successful plot to be on a log axis. So similar to having semilogy(x,y,'rx') for example.

Are there any other methods I could use?

enter image description here


Solution

  • How about "surf" it like a spectrogram?

    XX = log([104 122 138 159 149 167 184 164 190 158; 
              54  42  55  55  63  75  72  73  66  76; 
              15  22  28  21  23  28  32  47  32  40; 
              18  12  20  22  28  17  30  17  22  18; 
              10  7   14  10  14  11  14  20  16  10; 
               5   6   3   3   6   12  6   2   8   9; 
               4   8   9   2   5   3   3   12  7   7; 
               6   6   2   3   10  1   9   8   11  8]
    
    figure
    surf(XX, 'edgecolor', 'none'); view(0,90); axis tight;
    xlabel ('x')
    ylabel ('y')
    

    enter image description here

    NOTE:The first row represent the first row (104,122,138...) and row 8 represent row 8 (6,7,2....) Dark red = high value light blue = low value