Is it possible to add text to geobubble plots?

7 views (last 30 days)
I get this error when I try to add text to a geobubble plot:
Text cannot be a child of GeographicBubbleChart.
Is there any way to add text?

Accepted Answer

Kiran Felix Robert
Kiran Felix Robert on 24 Jul 2020
Hi John,
It is my understanding that you want to add text to the geobubble plot at a given position. This can be done using the uicontrols function provided you have the figure handle. One possible way to do this is as shown here, assuming you want to add a text ‘Text’ at [150.,150], as shown below (the table data is obtained from the example shown here)
h = figure('Name','GeoBubbleFig');
g = geobubble(h,tsunamis,'Latitude','Longitude'...
,'SizeVariable','MaxHeight','ColorVariable','Cause');
T = uicontrol(h,'Style','text','String','Text','Position',[150 150 50 20]);
Thanks,
Kiran
  2 Comments
Johannes Reimer
Johannes Reimer on 1 Feb 2022
I had the same problem and since it is not currently possible to use text with geobubble, i ended up using geoscatter:
h = figure('Name','Nice Bubble Plot');
g = geobubble(latiude,longitude,size,color,'MarkerFaceColor','flat');
text(latiude,longitude,name);
However, this solution comes with some downsides:
  1. To get the right size of the circles you have to fiddle around with the size variable (e. g. multiplying by 10). To show the size differences more clearly in my case, I used the squared size.
  2. The color isn't automatically chosen by the category. However, it can be defined as follows:
category = ['Category2','Category3','Category3','Category 1','Category2','Category3'] % And so on ...
categoryList = ['Category 1','Category2','Category3']; % List of possible categories
categoryColor = [ 0 0.619 0.878; % List of corresponding category colors
0.078 0.690 0.678;
0.415 0.690 0.137];
for i=1:size(latitude,2)
index(i) = find(strcmp(categoryList,category(i))); % Calculating the index of categoryColor for every element
end
% Substitute 'color' with 'categoryColor(index,:)' in the code snippet given above
% This will insert the corresponding RGB triplet for each element.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by