How do I add polygons to a map created with "geobubble"?

8 views (last 30 days)
I have some geographic data to display with a bubble plot, along with an SHP file containing polygonal regions which also want to be plotted (in this case "landareas.shp", which ships with MATLAB).  I can load the data with this code:
bubbleLats = [52.20 51.75 52.95 26.07];
bubbleLons = [0.13 -1.26 -1.15 50.56];
bubbleSizes = [1 2 3 4];
regions = readgeotable("landareas.shp");
Now I want to create a geographic plot containing both the bubbles and regions.  The result should look look something like this:
I have tried the following code:
figure
geobubble(bubbleLats, bubbleLons, bubbleSizes);
geolimits([50 60], [-15 5]);
geobasemap streets
mapshow(regions)
The bubbles are displayed, but "mapshow" fails with the following error:
Error using mapshow
Expected Parent to be one of these types:
matlab.graphics.axis.Axes
Instead its type was matlab.graphics.chart.GeographicBubbleChart.
Why is this not working? And how do I simultaneously plot the polygons and the bubbles on a map?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 May 2023
It is not possible to combine "geobubble" with other plots (using "hold on" or any other mechanism). However, the same effect can be achieved by replacing "geobubble" with "bubblechart" in the following way:
  1. Explicitly create a set geographic axes (using "geoaxes").
  2. Add a "bubblechart" which, unlike "geobubble", can be combined with other plots. If desired, a legend can be added with "bubblelegend" and the bubbles can be styled with the other "bubble-" functions like "bubblesize" and "bubblelim".
  3. Add extra plots with "geoplot".
The following code achieves the desired outcome:
figure
gx = geoaxes("Basemap","streets");
hold on
bubblechart(bubbleLats, bubbleLons, bubbleSizes, "Parent", gx);
geoplot(regions);
geolimits([50 60], [-15 5]);

More Answers (0)

Categories

Find more on Geographic Plots in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!