advanced Heatmap plotting question

조회 수: 6 (최근 30일)
chang liu
chang liu 2020년 8월 21일
댓글: chang liu 2020년 8월 31일
hi matlab experts, i have the following data matrix (see attached data.mat file)
i don't care about the all 0 column.
first column is x coordinate, second is y coordinate.
4th column is the value
as you can tell this is some sort of a scan that covers a 30x30 xy area
so for example, the first row of this data is -15,-15,0, 2921. it means, at x= -15 and y= -15, the data value is 2921 (ignore the 0)
question:
1) how do you plot a simple heatmap using this data?
2) more difficult: i really care about the values that are less than 3000. for me, any value less than 3000 means 'valid', any value above 3000 is invalid. so in addition to a normal heatmap that will just display the values in a temperature sense (like from cool to hot) , i really want another graph that clearly shows me what areas are 'valid' and what areas are 'invalid' in a black and white color sense (or green/red, whatever, as long as its just two colors) . one that i could easily look at and say, hey, at x=5 y=5, the value is invalid (above 3000)
thanks a lot!

답변 (1개)

Alan Stevens
Alan Stevens 2020년 8월 21일
The following will do it, though there are probably neater ways to do the colouring:
load('data.mat')
x = Z0(:,1); y = Z0(:,2); z = Z0(:,4);
x = reshape(x,31,31); y = reshape(y,31,31);z=reshape(z,31,31);
zlo = z<=3000;
C = 100*zlo;
surf(x,y,z,C)
  댓글 수: 10
Alan Stevens
Alan Stevens 2020년 8월 27일
If you add the colormap command just before the surf command like so:
...
C = 100*zlo;
colormap([0 0 0; 1 1 1]);
surf(x,y,z,C)
...
you will just get two colours (or just one for some situations!) .
The colormap above will result in black (the [0 0 0]) and white (the [1 1 1])..
By changing the values in the second row (i.e. the [1 1 1] values) you can adjust the colour (each of the digits must be between 0 and 1: they are RGB values). For example [127/255 1 212/255] is aquamarine (I can't think what yellow is off the top of my head).
chang liu
chang liu 2020년 8월 31일
worked like a charm

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by