MATLAB Answers

How do I plot points on a map in matlab?

168 views (last 30 days)
Shane on 10 Jun 2014
Commented: Mike D. on 7 Feb 2020
I have the mapping toolbox function. I brought up a map of the U.S. with lat/lon axes. All I need to do now I plot points on the map where certain cities/areas are. It does not need to be exact (but preferred), so any type of brush or something would work. How do I do this?
Here is what I have so far:
figure; ax = usamap({'CA','ME'});
set(ax, 'Visible', 'off')
latlim = getm(ax, 'MapLatLimit');
lonlim = getm(ax, 'MapLonLimit');
states = shaperead('usastatehi',...
'UseGeoCoords', true, 'BoundingBox', [lonlim', latlim']);
geoshow(ax, states, 'FaceColor', [0.5 0.5 1])
lat = [states.LabelLat];
lon = [states.LabelLon];
tf = ingeoquad(lat, lon, latlim, lonlim);
textm(lat(tf), lon(tf)) ...
  1 Comment
Geoff Hayes
Geoff Hayes on 11 Jun 2014
Unfortunately, I don't have the Mapping Toolbox, but at one time I did…and the use of textm was something I used to write annotation to the map given a latitude and longitude pair. Is that what you are doing? I also used plotm to "insert" shapes at certain locations too. Where are you getting stuck?

Sign in to comment.

Answers (1)

Mike D.
Mike D. on 15 Oct 2018
geoshow(LAT, LON, 'DisplayType', 'Point', 'Marker', '+', 'Color', 'red');
Mike D.
Mike D. on 7 Feb 2020
There is more than one way to change the color. You can interactively do it by clicking on the Edit Plot icon in the figure window (white arrow), then click on the symbol or text or curve item, then right-click and select 'Color'. I see what you mean that it still stays red. If you highlight the symbol, then type "get(gco)" in the command window, it will show the properties. It shows 'Color' property was modified correctly, but the 'MarkerEdgeColor' seems to be the dominating property for what color is displayed. Thus, you want to change the 'MarkerEdgeColor' instead of the 'Color' property. The command that created this symbol is the geoshow function (Mapping Toolbox function) and the resulting object it creates is technically a "Line" object. If you set the 'MarkerEdgeColor' to be 'auto', then the 'Color' property will work as specified.
Just so you know, Matlab R2018b came out with a new geoaxes function in core Matlab that doesn't require MappingToolbox and creates fantastic maps that easily pan/zoom with a mouse, are highly customizable. Geoaxes figures are much easier to create than Mapping Toolbox figures, but MappingToolbox figures are better in showing proper projections.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!