Generate a geographical heat map
83 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to generate a heat map on mapping toolbox.
Here I have the coordinates of the centers in my grid:
Lat = 54.2 + 0.1/6 * [11 9 7 5 3 1]' * ones(1,3) ;
Lon = 9.15 + 0.025 * ones(6,1) * [1 3 5] ;
coord = [ [Lat(:,1) , Lon(:,1)] ; [Lat(:,2) , Lon(:,2)] ; [Lat(:,3) , Lon(:,3)] ] ;
So coord is a 18 by 2 matrix, referring to the coordinates of 18 points.
Let us assume I want to assign a random value to each point, then I can define
values = rand(18, 1) .
How can I generate a heat map with such values in such locations?
How can I make each 'pixel' of the heat map like a sqare with size 0.05 by 0.033 degrees in longitude and latitude?
Thank you in advance for your help :)
2 个评论
Adam Danz
2021-1-20
A heatmap is a deptiction of 3D data in a 2D plane. Your Lat and Lon coordinates define the 2D plane but the 3rd dimension is missing in your description. The "values" vector is 1D so it's unclear how it should map onto the 2D surface of the heatmap.
采纳的回答
Adam Danz
2021-1-20
编辑:Adam Danz
2023-3-17
I think this is what you're looking for.
heatmap
Note the change in inputs from matrix to vector of unique values.
rng('default') % for reproducibility
Lat = 54.2 + 0.1/6 * [11 9 7 5 3 1]';
Lon = 9.15 + 0.025 * [1 3 5]' ;
values = rand(18, 1);
valuesMatrix = reshape(values(:),numel(Lat),numel(Lon));
hm = heatmap(Lon,Lat,valuesMatrix);
imagesc with text labels
rng('default') % for reproducibility
Lat = 54.2 + 0.1/6 * [11 9 7 5 3 1]';
Lon = 9.15 + 0.025 * [1 3 5]' ;
values = rand(18, 1);
valuesMatrix = reshape(values(:),numel(Lat),numel(Lon));
figure()
h = imagesc(Lon, Lat, valuesMatrix);
% reproduce heatmap's colormap
n=256;
cmap = [linspace(.9,0,n)', linspace(.9447,.447,n)', linspace(.9741,.741,n)'];
% Or
% cmap = sky(n); % R2023a or later
colormap(cmap);
axis xy
colorbar()
hold on
% Add text labels
[xTxt, yTxt] = ndgrid(h.XData, h.YData);
labels = compose('%.4f', h.CData');
th = text(xTxt(:), yTxt(:), labels(:), ...
'VerticalAlignment', 'middle','HorizontalAlignment','Center');
geodensityplot & geoscatter for geoaxes
The types of graphics objects that can be plotted to geographic axes are limited. Some options are geobubble | geodensityplot | geoplot | geoscatter | geodensityplot; see the documentation for an updated list. The first two examples below use geodensityplot where each coordinate influences a radius of 3000 meters and the third demo uses geoscatter.
rng('default') % for reproducibility
Lat = 54.2 + 0.1/6 * [11 9 7 5 3 1]';
Lon = 9.15 + 0.025 * [1 3 5]' ;
values = rand(18, 1);
valuesMatrix = reshape(values(:),numel(Lat),numel(Lon));
[LatMatix, LonMatrix] = ndgrid(Lat,Lon);
figure()
tiledlayout(2,2)
nexttile
h = geodensityplot(LatMatix(:), LonMatrix(:), valuesMatrix(:),'Radius',3000);
nexttile
h = geodensityplot(LatMatix(:), LonMatrix(:), valuesMatrix(:),'Radius',3000,'FaceColor','interp');
nexttile
h = geoscatter(LatMatix(:), LonMatrix(:), 600, valuesMatrix(:), 'filled','Marker','s','MarkerFaceAlpha',.4);
[latlim, lonlim] = geolimits();
geolimits(latlim+(range(latlim)*.1),lonlim) % 10% lat axis increase
6 个评论
Adam Danz
2021-1-21
编辑:Adam Danz
2021-1-21
This is actually the first time I'm using geodensityplot and maybe the second time I've used geoscatter. The documentation I linked to contains lots of examples to follow. geodensityplot does not currently have an option to change the shape of the markers. But geoscatter does.
I've update the answer to suggest some solutions.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!