How could I plot geobubble and geoplot in the same figure?

19 views (last 30 days)
I wrote the code
% this code is shorten from my full version because importing steps is too long and irrelevant for this question
Data = struct; % this struct array contains earthquake data in form of 1*1 struct with 8 fields,
% 3 from all fields are latitude,longitude and magnitude data
shapefilename = 'myflielocation\myfile.shp'; % this file contain fault line to plot with earthquake events location
S = shaperead(shapefilename, 'UseGeoCoords', true);
fig = figure;
geobubble(fig,,sortData.lon,sortData.mag,'Basemap', 'grayterrain');
After tried several times, The message "Adding GeographicBubbleChart to geoaxes is not supported Turn hold off." always show in the command window
It is possible to plot geobubble and use hold on or similar fucntion to use geoplot function within the same figure?
The cause of this question is I want to plot line and bubbles data in the same figure.
Before, I have tried following steps in
by replacing some codes
han = figure;
fg1 = geobubble(han,lat,lon,weight,'Basemap', 'grayterrain');
geolimits(f1, [LatLimit_a LatLimit_b], [LonLimit_a LonLimit_b]);
ax = geoaxes(eq,'Position',get(fg1,'Position'));
gg = geoplot(ax,lat,lon);
alpha(ax, 0.2);
ax.Visible = 'off';
geolimits(ax, [LatLimit_a LatLimit_b], [LonLimit_a LonLimit_b]);
The problem is the plot data is adjustable in figure window, not fix like using hold command in normal plot.
If my first question is impossible. Any alternating way exist? I need fixed data and axes.
Thank you.
  1 Comment
David Kelly
David Kelly on 13 Aug 2020
I am also looking to plot lines and other data over my geobubble plot. DId you find any solutions?

Sign in to comment.

Answers (1)

jonas on 13 Aug 2020
This is not a very good solution, but its something. It seems you cannot use plotm() etc. from the mapping toolbox in the same axes as a geobubble() plot. My solution was to overlay a second axes. For some reason MATLAB returns an error related to "Nextplot" if you add a map axes after geobubble, unless you first add a normal axes.
So, after a lot of experimenting this is the result. Note that the second axis is not perfectly aligned with the geobubble for unknown reason. You can play around with the position of the figure and the second axis to make it perfectly aligned.
tsunamis = readtable('tsunamis.xlsx');
tsunamis.Cause = categorical(tsunamis.Cause);
ax(1) = geobubble(tsunamis,'Latitude','Longitude', ...
fig = gcf;
fig.Position = [100 100 900 500]
%for some reason you have to add this invisible axes before axesm
ax(2) = axesm('MapProjection','mercator',...
ax(2).Position = ax(1).Position
ax(2).Color = 'none';
Feng Cheng
Feng Cheng on 22 Apr 2021
It looks like the overlap points are a little off from the actual point?

Sign in to comment.


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!