- https://www.mathworks.com/help/stats/gname.html
- https://www.mathworks.com/help/matlab/ref/gtext.html
gname does work for interactive labeling (at least in R2023a) for points plotted with geoplot. Any other suggestions?
1 次查看(过去 30 天)
显示 更早的评论
In R2023a the gname function throws an error ("Unrecognized property Xlim for class GeographicAxes") when attempting to interactively label points on a map figure generated with the geoplot command. I could write my own interactive point labeling tool based on gtext, but .... any other suggestions before I go that route? Here's an example :
% Put 3 points on a map with geoplot
figure;
subplot(121)
geoplot([40:5:50],[-104:-10:-125],'o', 'MarkerFaceColor','b');
geobasemap streets
% Try to Label them with gname --- this will throw an error
try
gname({'1st','2nd','3rd'})
catch ME
fprintf('gname failed with exception:')
display(ME)
end
% Plot the same points on regular plot
subplot(122)
plot([-104:-10:-125],[40:5:50],'o', 'MarkerFaceColor','b');
xlabel('Latitude'); ylabel('Longitude')
% Labeling them with gname works fine
gname({'1st','2nd','3rd'})
0 个评论
回答(1 个)
Suraj Kumar
2024-3-21
Hi David ,
You can use “gname” function to label plots created by “plot” ,“scatter” ,”gscatter” ,”plotmatrix” and “gplotmatrix”. But not for plots created by “geoplot”.
This is due to the differences in the underlying data types, coordinate systems, and plot handling between standard MATLAB plots and geographic plots.
A workaround for labeling points on geographic plots would be to use “gtext” function with latitude and longitude coordinates.
figure;
subplot(121)
geoplot([40:5:50],[-104:-10:-125],'o', 'MarkerFaceColor','b');
geobasemap streets
% Labelling the points on the geoplot
gtext({'1st';'2nd';'3rd'})
% Plot the same points on regular plot
subplot(122)
plot([-104:-10:-125],[40:5:50],'o', 'MarkerFaceColor','b');
xlabel('Latitude'); ylabel('Longitude')
% Labeling them with gname works fine
gname({'1st','2nd','3rd'})
You might find these resources helpful:
Hope this helps!
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!