How can I change the line colour in a geoplot based on data?

19 views (last 30 days)
I am using the geoplot function to track different fishing boat movements and wanted the lines to have different colours based on the fishing method used; eg blue for trawling, yellow for nets, red for lines. I have tried a few different commands but haven't had any luck yet. Below is the code used to generate the geoplots so far:
boat = readtable('2014S.xlsx');
figure
lat1 = boat.Latitude(vms.ID == 1);
lon1 = boat.Longitude(vms.ID == 1);
geoplot(lat1,lon1,'.-','DisplayName','1');
hold on
lat2 = boat.Latitude(vms.ID == 2);
lon2 = boat.Longitude(vms.ID == 2);
geoplot(lat2,lon2,'.-','DisplayName','2');
lat3 = boat.Latitude(vms.ID == 3);
lon3 = boat.Longitude(vms.ID == 3);
geoplot(lat3,lon3,'.-','DisplayName','3');
%GeoLimits
nlat = [49.1500 51.0000];
nlon = [-7.0000 -4.3000];
%Legend
lgd = legend;
lgd.FontSize = 12;
lgd.Title.String = '2014 Data';

Answers (1)

darova
darova on 9 Aug 2021
Try set
h1 = geoplot(..);
set(h1,'color','r')
  2 Comments
BRENDON QUEIROZ
BRENDON QUEIROZ on 9 Aug 2021
Thank you, that has helped me change the colour freely but I want to have each boat to be coloured based on the fishing method they used which I have in my original data spreadsheet. Is there a way I can do that?
darova
darova on 11 Aug 2021
Maybe you mean this
[x,y] = pol2cart((0:.1:2*pi),1);
% x(end) = nan;
cmap = rand(5,3); % 5 colors - 5 methods (RGB columns)
ii = randi(5,[numel(x) 1]); % numbers 1 .. 5
cmap = cmap(ii,:); % mix colors
p.vertices = [x(:) y(:)]; % points
tmp = 1:numel(x);
p.faces = [1:tmp(end-1); 2:tmp(end)]'; % connection of points
p.faceVertexCData = cmap; % color data
patch(p,'edgecolor','interp','linewidth',2)

Sign in to comment.

Categories

Find more on Geographic Plots in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!