I would like to add different colors in an interactive geobubble graph
4 views (last 30 days)
Show older comments
Hi,
I am trying to do an interactive goebubble graph where plots CO2 emissions (data) from a excel table. The excel containes: company, latitude, longitude, activity and emissions.
I created a listbox with uicontrol in which you can choose the Activity and then the geobubble graph shows the emission from the companies under this activity. I did that you can choose multiple activities and I would like to assign different colors in those activities in the geobubble graph.
If anyone could help or advise me. I would appreciate it.
Thank you.
I leave the code here. I am not really good at programming so it will probably need a lot of corrections.
% Read data from Excel file and create Table in matlab
t = readtable("file.xlsx");
% Extract the columns of data you want to use
latitude = t.latitude;
longitude = t.longitude;
emissions = t.emissions;
activity = categorical(t.activity);
% Create a figure
f = figure;
% Create a listbox menu to choose the category
categories = unique(activity);
lb = uicontrol('Style', 'listbox',...
'String', categories,...
'Min', 0, 'Max', 2,...
'Position', [20 340 100 150],...
'Callback', @changeCategories);
changeCategories(lb, []);
% Callback function for listbox
function changeCategories(lb, ~)
selectedCategories = categories(lb.Value);
idx = ismember(activity, selectedCategories);
geobubble(latitude(idx), longitude(idx), emissions(idx),'SizeLegendTitle','Emissions CO2 [kt]');
title('CO2 Emissions in Sweden by activity: ');
end
0 Comments
Answers (1)
Sulaymon Eshkabilov
on 5 Feb 2023
Here is the code that shall give different colors:
% Read data from Excel file and create Table in matlab
t = readtable("file.xlsx");
% Extract the columns of data you want to use
latitude = t.latitude;
longitude = t.longitude;
emissions = t.emissions;
activity = categorical(t.activity);
% Create a figure
f = figure;
% Create a listbox menu to choose the category
categories = unique(activity);
lb = uicontrol('Style', 'listbox',...
'String', categories,...
'Min', 0, 'Max', 2,...
'Position', [20 340 100 150],...
'Callback', @changeCategories);
changeCategories(lb, []);
% Callback function for listbox
function changeCategories(lb, ~)
selectedCategories = categories(lb.Value);
ACT = categorical(t.actvity);
idx = ismember(activity, selectedCategories);
geobubble(latitude(idx), longitude(idx), emissions(idx),'SizeLegendTitle','Emissions CO2 [kt]', ...
ACT);
title('CO2 Emissions in Sweden by activity: ');
end
See Also
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!