gname does work for interactive labeling (at least in R2023a) for points plotted with geoplot. Any other suggestions?

3 visualizzazioni (ultimi 30 giorni)
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'})

Risposte (1)

Suraj Kumar
Suraj Kumar il 21 Mar 2024
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!

Categorie

Scopri di più su Geographic Plots in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by