I would like to add different colors in an interactive geobubble graph

4 Ansichten (letzte 30 Tage)
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

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 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
  2 Kommentare
Gemma Bruguera Matute
Gemma Bruguera Matute am 5 Feb. 2023
I got this error:
Error using geobubble
Expected colordata to be one of these types:
categorical
Gemma Bruguera Matute
Gemma Bruguera Matute am 5 Feb. 2023
I have fixed it. But thank you so much for your input.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by