advanced Heatmap plotting question

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!

Respuestas (1)

Alan Stevens
Alan Stevens el 21 de Ag. de 2020
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 comentarios

Alan Stevens
Alan Stevens el 21 de Ag. de 2020
By looking from the top you get:
chang liu
chang liu el 21 de Ag. de 2020
wow this is neat Alan.
is there a command that makes the figure just show up in a 2D fashion? (right now have to use mouse and drag it around a bit to rotate to the right view)
thanks
chang liu
chang liu el 21 de Ag. de 2020
hmmm... i found that by doing a
figure;hold on;
before you do the surf, it makes it into 2D
Alan Stevens
Alan Stevens el 21 de Ag. de 2020
Great!
chang liu
chang liu el 22 de Ag. de 2020
hey... this may be asking too much but.. do you know a way to overlay a circle onto the existing heatmap? like i've manually done here. just a circle having certain radius and center, i don't need the 'x' markers or any other annotations that i've drawn here. they just there to help me draw this circle manually.
the reason is i need to very quickly gauge using my eye (out of hundreds of figures) if the valid area (yellow zone) meets certain minimal requirement such as having a minimal radius (bigger is ok) . sort of like a 'limit line' in converntional xy plots.
attached file as example
also, figure is already 2D, as i did the 'figure;hold on;' thing to create the figure in the first place.
Try this:
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)
xlabel('x'), ylabel('y')
view(180,-90)
hold on
theta = zeros(360,1);
for i = 1:361; theta(i) = (i-1)*pi/180; end
r = 10; % You will have to decide this yourself
xc = r*cos(theta); yc = r*sin(theta);
plot(xc,yc)
chang liu
chang liu el 24 de Ag. de 2020
thanks! worked like a charm
chang liu
chang liu el 27 de Ag. de 2020
alan
found another issue. so whenever the data is entirely below the threshold we set (3000), the color goes to cyan. can you help? attached sample data
ideally it should be all yellow.
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 el 31 de Ag. de 2020
worked like a charm

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 21 de Ag. de 2020

Comentada:

el 31 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by