Reputation: 1
I have this map of California I generated with the following code:
states = geoshape(shaperead('usastatehi', 'UseGeoCoords', true));
figure
ax = usamap('california');
oceanColor = [.5 .7 .9];
setm(ax, 'FFaceColor', oceanColor)
geoshow(states)
title({ 'California map'})
Now I want to plot specific points on the map using latitude and longitude coordinates. I can't "guesstimate" because I have to plot 100 or so points. How do I do that? I look everywhere and couldn't find a syntax. Thanks.
Upvotes: 0
Views: 8163
Reputation: 124563
Use plotm
or linem
, the equivalent of MATLAB's plot
and line
functions respectively (they accept the same "line style specifications").
Here is an example:
% California map axes
figure; ax = usamap('california');
setm(ax, 'FFaceColor', [.5 .7 .9])
title('California map')
% read shapefile of US states with names and locations
states = geoshape(shaperead('usastatehi.shp', 'UseGeoCoords', true));
% display map
geoshow(states, 'Parent',ax)
% find states within the shown axes limits (California and Nevada)
latlim = getm(ax, 'MapLatLimit');
lonlim = getm(ax, 'MapLonLimit');
idx = ingeoquad(states.LabelLat, states.LabelLon, latlim, lonlim);
% latitude/longitude coordinates and corresponding labels
lat = states(idx).LabelLat;
lon = states(idx).LabelLon;
txt = states(idx).Name;
% plot coordinates
%plot(lat, lon, 'rx')
linem(lat, lon, 'LineStyle','none', 'LineWidth',2, 'Color','r', ...
'Marker','x', 'MarkerSize',10)
textm(lat, lon, txt, 'HorizontalAlignment', 'left', 'VerticalAlignment','top')
Upvotes: 1