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

4 ビュー (過去 30 日間)
Gemma Bruguera Matute
Gemma Bruguera Matute 2023 年 2 月 4 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by