I would like to add different colors in an interactive geobubble graph
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Sulaymon Eshkabilov
2023-2-5
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!