在MATLAB中在地图上绘制点 [英] Plotting Points on a Map in MATLAB

查看:1713
本文介绍了在MATLAB中在地图上绘制点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在纽约州地图上绘制不同的位置.我目前的代码绘制了整个北美地区的图,因为我找不到如何绘制一个州的图.我正在尝试为纽约州设定纬度和经度限制,但仍然给了我整个国家.

I want to plot different locations on a map of NY state. My current code plots the entirety of North America because I couldn't find how to plot just one state. I'm trying to set the latitude and longitude limits to the state of NY, but it's still giving me the entire country.

此外,当我执行hold all(或hold on)并尝试绘制点时,会弹出另一个图,该图带有我指定的标题,但只是一个空白的白色正方形.

In addition, when I do hold all (or hold on) and try to plot the points, I get another figure that pops up with the title I specified, but just a blank, white square.

另一个相关的问题是,一旦我绘制了点,就必须知道它们是什么点.如果我在单独的单元格数组中有名称,那么我如何让MATLAB基于哪些坐标(存储在单独的列中)与哪个名称(如果名称存储在另一列中)相对应的方式标记点?

Another related question is that once I get the points plotted, I have to know what points they are. If I have the names in a separate cell array, how can I have MATLAB label the points based on which coordinates (which are stored in a separate column) correspond with which name (if the names are stored in yet another column)?

%% Plot map
latlim = [39 47];
lonlim = [-81 -70];

ax = worldmap('USA');
load coast
geoshow(ax, lat, long,...
'DisplayType', 'polygon', 'FaceColor', [.45 .60 .30])
states = shaperead('usastatelo', 'UseGeoCoords', true, 'BoundingBox', [lonlim' latlim']);
axesm('lambert', 'MapLatLimit', latlim, 'MapLonLimit', lonlim);
faceColors = makesymbolspec('Polygon',...
    {'INDEX', [1 numel(states)], 'FaceColor', ...
    polcmap(numel(states))}); % NOTE - colors are random
geoshow(ax, states, 'DisplayType', 'polygon', ...
  'SymbolSpec', faceColors);
figure('Color', 'white')

title('PM2.5 Site in New York State in 2012');

hold all

% Plot points
axesm('lambert', 'MapLatLimit', latlim', 'MapLonLimit', lonlim');
datalat = str2double(datalat);
datalon = str2double(datalon);
scatterm(datalat, datalon)

推荐答案

您可以使用usamap('New York')获取美国状态地图,并使用textm绘制覆盖文本.在这里,图中绘制了25个随机点及其标签.

You can get a USA state map with usamap('New York') and plot an overlay text with textm. Here, 25 random points and their label are plotted on the figure.

以下情节

是由

latlim = [39 47];
lonlim = [-81 -70];

figure('Color','w');
usamap('New York')
shi = shaperead('usastatehi', 'UseGeoCoords', true,...
            'Selector',{@(name) strcmpi(name,'New York'), 'Name'});
geoshow(shi, 'FaceColor', [0.3 1.0, 0.675])
textm(shi.LabelLat, shi.LabelLon, shi.Name, 'HorizontalAlignment', 'center')

nb_point = 25;
LAT = latlim(1) + (latlim(2)-latlim(1)).*rand(nb_point,1);
LON = lonlim(1) + (lonlim(2)-lonlim(1)).*rand(nb_point,1);
h = geoshow(LAT, LON, 'DisplayType', 'Point', 'Marker', '+', 'Color', 'red');
textm(LAT, LON+0.3, num2str((1:nb_point)'), 'FontSize',14)

这篇关于在MATLAB中在地图上绘制点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆