我有一张用标签绘制点的地图。现在,在标签靠得很近的地方,标签会重叠。我看到有些人建议使用 textbp (FileExchange),但我从单元格数组中的列中获取标签,因此该函数不起作用。我怎样才能使标签放置在离点足够远的地方,以便清楚地看到所有标签?如果不清楚哪个标签适用于哪个情节,也许可以添加箭头?
数据是这个文件:https ://www.dropbox.com/sh/li3hh1nvt11vok5/4YGfwStQlo 。我从这个文件中提取数据并对其进行排序,找到唯一值,然后用它来绘制点。
这是我的脚本的地图部分:
%% Use function to read in 2012
% Format: data = ('filename', 'delimiter')
filename = ('PM2.5_NY_2012.csv'); % PM2.5 88101 and 88502 data from NY
data = read_mixed_csv(filename,', '); % 2012 must have ',' taken out first. DO NOT need to use for 2011
data = read_mixed_csv(filename,'"'); % Creates cell array of data (2011, 2012)
data = regexprep(data, '^"|"$',''); % Gets rid of double quotes at the start and end of the string
data = data(:,2:2:end); % 2012. Do it only if there are blank columns. Keep only the even cells because the odd ones are just commas
PM25_NY_2012 = data;
%% Pull data of a specific parameter (Latitude and Longitude - Columns 20 and 21)
% Pull out data with Local Conditions only (Locations differ compared to Acceptable PM2.5
data_Loc = data(strcmp('PM2.5 - Local Conditions', data(:,10)),:);
% Pull out data with Acceptable PM2.5 AQI only
data_Acc = data(strcmp('Acceptable PM2.5 AQI & Speciation Mass', data(:,10)),:);
%% Find index for the first unique lat and lon
% Local Conditions
[C,ia,ic] = unique(data_Loc(:,2));
DupIndex = setdiff(1:size(data_Loc(:,2)), ia);
data_Loc(DupIndex,:) = [];
datalat_Loc = data_Loc(:,19);
datalon_Loc = data_Loc(:,20);
% Acceptable PM2.5
[C, ia,ic] = unique(data_Acc(:,2));
DupIndex = setdiff(1:size(data_Acc(:,2)), ia);
data_Acc(DupIndex,:) = [];
datalat_Acc = data_Acc(:,19);
datalon_Acc = data_Acc(:,20);
%% Plot map
latlim = [39 47];
lonlim = [-81 -70];
figure('Color','w');
% Plot for Acceptable PM2.5
subplot(1,2,1)
usamap('New York'); % 'Vermont', 'Massachusetts', 'Rhode Island', 'Connecticut', 'New Jersey', 'Pennsylvania', 'Delaware', 'Maryland')
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')
[row,col] = size(datalat_Acc);
nb_point = row;
LAT = str2double(datalat_Acc);
LON = str2double(datalon_Acc);
h = geoshow(LAT, LON, 'DisplayType', 'Point', 'Marker', '*', 'Color', 'red');
textm(LAT, LON,(data_Acc(:,2))', 'FontSize',8)
title('PM2.5 Sites in New York State in 2012 - Acceptable PM2.5 AQI & Speciation Mass');
hold all
% Plot for Local Conditions
subplot(1,2,2)
% figure('Color','w');
usamap('New York'); % 'Vermont', 'Massachusetts', 'Rhode Island', 'Connecticut', 'New Jersey', 'Pennsylvania', 'Delaware', 'Maryland')
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')
[row,col] = size(datalat_Loc);
nb_point = row;
LAT = str2double(datalat_Loc);
LON = str2double(datalon_Loc);
h = geoshow(LAT, LON, 'DisplayType', 'Point', 'Marker', '+', 'Color', 'red');
textm(LAT, LON,(data_Loc(:,2))', 'FontSize',5)
title('PM2.5 Sites in New York State in 2012 - Local Conditions');
所以问题在于以textm
重叠方式绘制标签的脚本部分。