- Color: Currently, you have set the color of the text and arrow to white ('Color', [1 1 1]'). Since your background is also white, the text and arrow become invisible.
- Third argument in "textm": The "textm" function takes optional arguments. The "4000" you provided is likely causing an issue.
How to add a left pointing arrow with annotation to a plotted DEM in MATLAB?
1 次查看(过去 30 天)
显示 更早的评论
I have been trying to add a left pointing arrow with the label 'Mt Everest' (both in white) to an extracted portion of a DEM. This is the code I have to get to this point, however the arrow and text does not appear when I run the script despite the rest of the properties working.
% extract_mt_everest_dem
%% Load the Mt Everest DEM data
[DEM, DEM_R] = geotiffread('aster_gdem_mosaic_UTM_crop.tif');
DEM_info = geotiffinfo('aster_gdem_mosaic_UTM_crop.tif');
% Manage NoData cells to make then NaN
DEM(DEM<=0) = NaN;
% Extract the lat and lon values for each cell within the data
% Create an index variable
idx = 1:length(DEM(:));
% Get the indices for each cell in the DEM
[I,J] = ind2sub(size(DEM),idx);
clear idx
% Convert the cell indices into projected coordinates
[x,y] = pix2map(DEM_info.RefMatrix, [I(:) J(:)]);
clear I J
% Reshape the x and y vectors to a grid the same size as the data
x_grid = reshape(x,size(DEM));
y_grid = reshape(y,size(DEM));
% Calculate the lat and lon values from the projected coordinates
[lat,lon] = projinv(DEM_info, x(:), y(:));
clear x y
% Reshape the lat and lon vectors to a grid the same size as the data
lon_grid = reshape(lon,size(DEM));
lat_grid = reshape(lat,size(DEM));
clear lat lon
%% Choose the point of interest (POI): Mt Everest
mt_everest = [27.986065 86.922623];
[mt_everest_X, mt_everest_Y] = projfwd(DEM_info, mt_everest(1), mt_everest(2));
%% Calculate distance from Aoraki Mt Cook
x_diff = x_grid - mt_everest_X;
y_diff = y_grid - mt_everest_Y;
% Find the indices of the bounding box of cells within a specified ditance of 20x20 km
max_dist = 10000; % (m)
row_start = find(abs(y_diff(:,1))<=max_dist, 1);
row_end = find(abs(y_diff(:,1))<=max_dist, 1, 'last');
col_start = find(abs(x_diff(1,:))<=max_dist, 1);
col_end = find(abs(x_diff(1,:))<=max_dist, 1, 'last');
% Extract the ROI from whole array using indexing
DEM_ROI = DEM(row_start:row_end,col_start:col_end);
lat_grid_ROI = lat_grid(row_start:row_end,col_start:col_end);
lon_grid_ROI = lon_grid(row_start:row_end,col_start:col_end);
%% Make a map to display the subset data
% Set the font size
font_size = 18;
set(0, 'DefaultAxesFontSize', font_size);
% Make the figure the size of the full screen
figure('units','normalized','outerposition',[0 0 1 1]);
% Set the backrgound colour to white
set(gcf,'color','w');
% Make a projected map axis using worldmap
ax = worldmap([nanmin(lat_grid_ROI(:)) nanmax(lat_grid_ROI(:))],[nanmin(lon_grid_ROI(:)) nanmax(lon_grid_ROI(:))]);
% Set axis font size to 18
setm(ax,'FontSize',font_size);
hold on % to allow for overplotting
pcolorm(lat_grid_ROI, lon_grid_ROI, DEM_ROI);
cmap = landcolor; % get the landcolour colour map
colormap(cmap); % use the landcolour colour map
shadem; % shade the DEM to highlight the relief
hbar = colorbar('northoutside','fontsize',font_size); % create a colourbar
set(get(hbar,'Xlabel'),'String','Elevation (m)'); % add a colourbar label
% Add a scale bar
scalebar('color',[0 0 0],'FontSize',font_size,'location','southeast');
% Add a label showing Mt Everest with a left-pointing arrow
b = textm(mt_everest(1), mt_everest(2), 4000,'\leftarrow Mt. Everest','FontSize', font_size,'Color',[1 1 1]);
uistack(b, 'top');
close
Anyone know how to get my arrow and label to appear?
0 个评论
回答(1 个)
Abhinaya Kennedy
2024-5-7
Hi Adele,
The issue with your code for adding the arrow and label is twofold:
Here's the corrected code snippet for adding the label:
b = textm(mt_everest(1), mt_everest(2), '\leftarrow Mt. Everest','FontSize', font_size,'Color', 'black');
uistack(b, 'top');
You can adjust the position of the label using the first two arguments of "textm". These represent the latitude and longitude coordinates. Consider using a different font style for the arrow using the "FontName" property in the "textm" function (e.g., 'Symbol'). This might provide a clearer left-pointing arrow symbol.
You can also take a look at the documentation for more information on "textm":
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!