user3536870
user3536870

Reputation: 249

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

Upvotes: 2

Views: 2418

Answers (2)

Herman Wilén
Herman Wilén

Reputation: 195

Matlab also provides a heatmap function.

>> 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];
>> heatmap(X)

ans = 

  HeatmapChart with properties:

    ColorData: [8×10 double]

  Show all properties

The following plot appears: Heatmap of the matrix X

Upvotes: 4

GameOfThrows
GameOfThrows

Reputation: 4510

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

Upvotes: 4

Related Questions