您好,
我想用 2D 格式的 2 个变量(纬度和经度)表示数据。该值由颜色和 2 个变量表示为 2 轴,我使用轮廓函数来绘制我的数据。所有数据都来自一个 xlsx 文件,我把它放在一个矩阵中。
Locations = xlsread('Availability results.xlsx');
column_numberloc = 1; % Column in the locations file containing the number of the locations
column_latitude = 2; % Column in the locations file containing the latitude of the locations
column_longitude = 3; % Column in the locations file containing the longitude of the locations
column_availability = 4; % Column in the locations file containing the availability of the locations
min_latitude = min(Locations(:,column_latitude));
max_latitude = max(Locations(:,column_latitude));
min_longitude = min(Locations(:,column_longitude));
max_longitude = max(Locations(:,column_longitude));
max_availability = max(Locations(:,column_availability));
min_availability = min(Locations(:,column_availability));
longitude = Locations(:,column_longitude);
latitude = Locations(:,column_latitude);
Contour = zeros(23,17);
for numerofile=1:204
[coord_x,coord_y] =transformation(Locations(numerofile,column_latitude),Locations(numerofile,column_longitude));
Contour(coord_x,coord_y) = Locations(numerofile,column_availability);
end
for i=1:23
for j=1:17
if Contour(i,j) == 0
Contour(i,j) = NaN;
end
end
end
cMap=jet(256);
figure(1);
x = linspace(min_longitude,max_longitude,17);
y = linspace(min_latitude,max_latitude,23);
newpoints = 100;
[xq,yq] = meshgrid(linspace(min(x),max(x),newpoints),linspace(min(y),max(y),newpoints ));
Contourq = interp2(x,y,Contour,xq,yq,'linear',max_availability);
[c,h]=contourf(xq,yq,Contourq,100);
%[c,h]=contourf(x,y,Contour,50);
set(h, 'edgecolor','none');
colormap(cMap);
cb=colorbar;
caxis([min_availability max_availability]);
该转换功能,可以让我把在轮廓矩阵中的所有数据,因为它经度和纬度的行和列相关联。
我为每个等于零的数据放置了一个 NaN 以更好地查看我的数据,我得到了这个:interpolation_linear
这很好,但我希望这些数据接近:没有插值
所以,我决定将线性插值更改为“最近”插值,我得到了这个:interpolation_nearest
我可以看到更多数据,但等高线图不像线性插值那样平滑。
我看过很多关于如何制作平滑等高线图的帖子(这就是我找到函数“interp2”的方式),但我认为我的问题来自 NaN 数据,这使我无法在 NaN 值之间的边缘绘制平滑的等高线图其余的像第一张图像,但像第三张图像一样有足够的数据。
我的问题是:您知道如何通过最近的插值获得具有足够数据的平滑边缘轮廓图,但具有像第一张图像一样的良好视觉效果吗?
非常感谢你
由于您是在方形网格上进行插值,因此您可以直接显示带有imagesc
. 好处是可以访问AlphaData
图像对象的属性,可以作为显示遮罩使用。
r=rand(50); % random 50x50 array
r(11:20,11:20)=NaN; % some hole filled with NaN
imagesc(r) % show the image, with NaN considered as the lowest value in color scale
imagesc(r,'AlphaData',~isnan(r)) % show the image, with NaN values set as fully transparent
您还可以:
interp2
,甚至可能使用'cubic'
提高平滑度的参数AlphaData
。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句