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

조회 수: 4 (최근 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

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by