필터 지우기
필터 지우기

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'})

답변 (1개)

Suraj Kumar
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:
  1. https://www.mathworks.com/help/stats/gname.html
  2. https://www.mathworks.com/help/matlab/ref/gtext.html
Hope this helps!

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by