How can I snap my data point to the border for a colormap/heatmap?

조회 수: 6 (최근 30일)
LEE WEI JIE DANIEL
LEE WEI JIE DANIEL 2021년 2월 20일
댓글: Image Analyst 2021년 2월 22일
Hey everyone!
I am trying to do a color map/heat map of Asia continent. I have my values for my color map in terms of a 70x110 double array and I want to plot at a resolution of it at every 0.5 latitude and longitude.
I have tried the following:
load coastlines
X = [0.25:0.5:34.75] ; % latitude
Y = [65.25:0.5:119.75]; %longitude
Q = pcolor(Y,X,A);
Q.FaceColor = 'interp';
set(Q, 'EdgeColor','none')
H= colormap(flipud(jet));
hold on
coast = plot(coastlon, coastlat,'Color','k');
grid on;
colorbar
xlabel('Longitude')
ylabel('Latitude')
I am able to get a decent looking map but I realised that due to the resolution the colored box is out of the coast border and it is not presentable for me. Is there any solution to this? Also is there anyway to countries borders drawn as well?

답변 (2개)

darova
darova 2021년 2월 20일
Here is the idea
  • create new mesh for the contour
  • interpolate values
  댓글 수: 5
darova
darova 2021년 2월 21일
  • How would they fit into your x1s, x2s, y1s, y2s and z1s and z2s!
Your x1,y1,z1 should be matrices to use interp2. Maybe use meshgrid to convert your vectors into matrices
% vectors
X = [0.25:0.5:34.75] ; % latitude
Y = [65.25:0.5:119.75]; %longitude
% matrices (can be used with interp2)
[X1,Y1] = meshgrid(X,Y);
Here is another example using initmesh (triangulation). It's more universal
clc,clear
r = rand(1,30)+1;
t = linspace(0,2*pi-0.1,30); % unclosed contour
[x,y] = pol2cart(t,r);
gd = [2;length(x);x(:);y(:)]; % geometry description
dl = decsg(gd); % decomposition
[p,e,t] = initmesh(dl); % triangulation
% create structure for visualization
pp1.faces = t(1:3,:)';
pp1.vertices = p;
pp1.facecolor = 'green';
patch(pp1)
Note: contour for triangulation should be unclosed (first and last points are different)
LEE WEI JIE DANIEL
LEE WEI JIE DANIEL 2021년 2월 21일
Hello @darova thanks once again! Could I trouble you once again
I tried using the new set of codes together with the m1.m file you gave in the previous comment. I managed to process till the following: (A is my 70 x 110 matrix)
X = [0.25:0.5:34.75] ; % latitude
Y = [65.25:0.5:119.75]; %longitude
% matrices (can be used with interp2)
[X1,Y1] = meshgrid(X,Y);
load coastlines
B = coastlon;
C = coastlat;
z2 = interp2(X,Y,A',X,Y);
cla
plot(B',C')
hold on
plot(B,C)
pcolor(Y,X,A)
plot(Y,X,'.-b')
hold off
I managed to generate this plot but its kind off like my previous plot I shown above. Here the snapping to the coast borders are still not happening and I twigged pcolor(Y,X,A) from the original which is supposed to be pcolor(C,B,Z2) because my Z2 yields no color matrix and its a 9685x1 filled with NaNs while your Z2 was a 5x20 with different values that were used.

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


Image Analyst
Image Analyst 2021년 2월 21일
pcolor() does not show all the values as pixels/tiles. It leaves off the last row and column. Or, actually, it has the pixels as edges in the image, not as the center of the little colored tiles. If you want to plot lines going to the center of the colored boxes, then don't use pcolor(), use imshow() instead. Then put hold on and call plot().
  댓글 수: 8
LEE WEI JIE DANIEL
LEE WEI JIE DANIEL 2021년 2월 22일
X = [0.25:0.5:34.75] ; % latitude
Y = [65.25:0.5:119.75]; %longitude
For the Z value, randi(70,110)
that would generate similar matrix of the colored background
for the lines of the coast. I use load coastlines (I dont know if this is a map toolbox)
Image Analyst
Image Analyst 2021년 2월 22일
Sorry I can't help unless you supply data. I do not have coastlines.mat.

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

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by