how to use geoplot/geobubble with hold on

48 views (last 30 days)
I have many longitiud and latitiud and I want to draw them with geobuble/geoplot. But I don't want them all to be the same color, for example I want the first 20 to be red and the next 15 to be yellow and .... . so I want to group them and draw each group separately and at the end see my map with different colors . When I used hold on in a for loop, I get an error

Answers (1)

Vaibhav
Vaibhav on 13 Oct 2023
Hi Hamed,
I understand that you are looking for a method to use "hold on" with "geobubble".
According to the MathWorks Documentation provided below, the "geobubble" feature does not support the use of the "hold" command.
Nevertheless, using "hold on" with "geoplot" allows you to depict longitude and latitude points with varied colors. Refer to the code below for implementing "geoplot" to showcase points in different colors.
% Define the latitude and longitude coordinates of the points
lat = [32.30 33.92 35.17 36.98 37.69 38.34];
lon = [-91.05 -91.18 -90.09 -89.11 -89.52 -90.37];
% Calculate the number of points
numPoints = numel(lat);
% Determine the indices for each color
blueIndices = 1:ceil(numPoints/3); % Indices for blue color
redIndices = ceil(numPoints/3)+1:ceil(2*numPoints/3); % Indices for red color
greenIndices = ceil(2*numPoints/3)+1:numPoints; % Indices for green color
% Plot the points using different colors
geoplot(lat(blueIndices), lon(blueIndices), "--gs", "LineWidth", 2, ...
"MarkerSize", 10, "MarkerEdgeColor", "b", "MarkerFaceColor", [0.5 0.5 0.5]) % Plot blue points
hold on
geoplot(lat(redIndices), lon(redIndices), "--gs", "LineWidth", 2, ...
"MarkerSize", 10, "MarkerEdgeColor", "r", "MarkerFaceColor", [0.5 0.5 0.5]) % Plot red points
geoplot(lat(greenIndices), lon(greenIndices), "--gs", "LineWidth", 2, ...
"MarkerSize", 10, "MarkerEdgeColor", "g", "MarkerFaceColor", [0.5 0.5 0.5]) % Plot green points
hold off
% Set the limits of the map
geolimits([31.60 38.91], [-95.61 -84.27])
% Set the basemap style
geobasemap grayterrain
For more information about "geoplot" you can refer to the following MathWorks documentation:
Hope this helps!

Categories

Find more on Geographic Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!