【发布时间】:2019-03-22 01:13:27
【问题描述】:
你好
我想用 2D 格式的 2 个变量(纬度和经度)表示数据。该值由颜色表示,2 个变量作为 2 轴,我正在使用 contourf 函数来绘制我的数据。所有的数据都来自一个 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]);
transformation 函数允许我将所有数据放在等高线矩阵中,因为它将经度和纬度与行和列相关联。
我已经为每个等于零的数据放置了一个 NaN,以便更好地查看我的数据,我得到了这个: interpolation_linear
这很好,但我希望这些数据接近: Without interpolation
所以,我决定将线性插值更改为“最近”插值,我得到了: interpolation_nearest
我可以看到更多数据,但等高线图不像线性插值那样平滑。
我看过很多关于如何制作平滑等高线图的帖子(这就是我找到函数“interp2”的方式),但我认为我的问题来自 NaN 数据,它阻止我在边缘绘制平滑等高线图在 NaN 值和其他值之间,如第一张图像,但有足够的数据,如第三张图像。
我的问题是:你知道我怎样才能得到一个平滑的边缘轮廓图,这要归功于最近的插值,但具有像第一张图像一样漂亮的视觉效果?
非常感谢
【问题讨论】:
标签: matlab matlab-figure contour