マップ上に凡例を出す方法

6 views (last 30 days)
司 小川
司 小川 on 10 Mar 2021
Answered: takemoto on 11 Mar 2021
取得した緯度と経度のデータと心拍情報を地図上にヒートマップのような形でプロットしたのですが,凡例の出し方が分かりません。ご教授いただけますでしょうか。
下記はマップを書いた時のプログラミングコードと書いたマップです。この凡例を出したいです。
F = fillmissing(HF,'previous');
nBins = 50;
binSpacing = (max(F) - min(F))/nBins;
binRanges = min(F):binSpacing:max(F)-binSpacing;
% Add an inf to binRanges to enclose the values above the last bin.
binRanges(end+1) = inf;
% |histc| determines which bin each speed value falls into.
[~, FBins] = histc(F, binRanges);
lat = lat';
lon = lon';
FBins = FBins';
% Create a geographical shape vector, which stores the line segments as
% features.
s = geoshape();
for k = 1:nBins
% Keep only the lat/lon values which match the current bin. Leave the
% rest as NaN, which are interpreted as breaks in the line segments.
latValid = nan(1, length(lat));
latValid(FBins==k) = lat(FBins==k);
lonValid = nan(1, length(lon));
lonValid(FBins==k) = lon(FBins==k);
% To make the path continuous despite being segmented into different
% colors, the lat/lon values that occur after transitioning from the
% current speed bin to another speed bin will need to be kept.
transitions = [diff(FBins) 0];
insertionInd = find(FBins==k & transitions~=0) + 1;
% Preallocate space for and insert the extra lat/lon values.
latSeg = zeros(1, length(latValid) + length(insertionInd));
latSeg(insertionInd + (0:length(insertionInd)-1)) = lat(insertionInd);
latSeg(~latSeg) = latValid;
lonSeg = zeros(1, length(lonValid) + length(insertionInd));
lonSeg(insertionInd + (0:length(insertionInd)-1)) = lon(insertionInd);
lonSeg(~lonSeg) = lonValid;
% Add the lat/lon segments to the geographic shape vector.
s(k) = geoshape(latSeg, lonSeg);
end
wm = webmap('Open Street Map');
mwLat = 35.293818;
mwLon = 136.927917;
name = 'location';
iconDir = fullfile(matlabroot,'toolbox','matlab','icons');
iconFilename = fullfile(iconDir, 'matlabicon.gif');
wmmarker(mwLat, mwLon, 'FeatureName', name, 'Icon', iconFilename);
colors = autumn(nBins);
wmline(s, 'Color', colors, 'Width', 5);

Answers (1)

takemoto
takemoto on 11 Mar 2021
"legend"コマンドの様な直接的な方法は見当たらない様ですが、以下に代替案につい言及があります。

Categories

Find more on Board games in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!