Geoplot with bar chart for each zone

4 次查看(过去 30 天)
Hi,
I am really new to MATLAB and am trying to learn it very well for future positions. However, for now, I need to do a geoplot for 7 zones (Africa, Europe, Middle East, Asia Pacific, Euraisa, South & Central America and North America) that shows the change in their energy consumption by stacked bar chart in 8 different sectors for 2015 and 2021.
I would appreciate if anyone can give me a hint on how to do the code.
Thanks

回答(1 个)

Austin M. Weber
Austin M. Weber 2024-4-27
编辑:Austin M. Weber 2024-4-27
Assuming I understand what you're asking for, the following code should help get you started. Just note that this method requires the MATLAB Mapping Toolbox (also, I changed the name of your Excel file to 'CO2data.xlsx' for simplicity). In the example below, I show:
  1. How to extract data from specfic sheets in the Excel file (using the African data as an example).
  2. How to produce a map of the world with functions from the Mapping Toolbox.
  3. How to add new axes to the map on which you can visualize your data using a stacked bar chart.
% African data
filename = 'CO2data.xlsx';
africa2015 = readtable(filename,'FileType','spreadsheet','Sheet','Africa 2015',...
'ReadRowNames',true,'VariableNamingRule','preserve');
africa2021 = readtable(filename,'FileType','spreadsheet','Sheet','Africa 2021',...
'ReadRowNames',true,'VariableNamingRule','preserve');
variable_names = {'Industry','Transport','Residential','Commercial','Agriculture','Fishing','Nonspecified','Non-energy use'};
africa2015totals = africa2015{"Total",:};
africa2021totals = africa2021{"Total",:};
% CREATE A WORLD MAP
load coastlines
figure()
ax=axesm('braun','MapLonLimit', [-180 180],'MapLatLimit',[-60 90]);
fillm(coastlat,coastlon,'#d5d5d5')
tightmap()
framem()
gridm()
% CREATE A NEW AXES FOR EACH BAR CHART
% Example for Africa:
axes('Position',[0.500, 0.400, 0.250, 0.100]) % X,Y,width,height
bar(variable_names,[africa2015totals; africa2021totals],'stacked')
title('Africa')
legend(gca,'2015','2021','Location','eastoutside')
It will take a lot of trial-and-error to get all 7 bar charts located in the correct places if you're doing everything programmatically, so I recommend simply moving the charts with the tools in the Figure Window whenever you create the map in your MATLAB Desktop application. I hope this helps!
  1 个评论
Shamsoddin
Shamsoddin 2024-6-18
@Austin M. Weber, thanks for your response.
Unfortunately, the version of MATLAB I am using is 2023 and therefore, I recieve an empty box over a map. It does not show the graph inside it.
I want to draw a horizontal stacked bar chart that the shows the amount of different energy sources (Liquid and solid fossil fuels, Natural gas, Renewable energy, Biofuels and waste, Electricity, Heat) for "residential" and "commercial and public services" buildings for 2015 and 2021. I want the "residential" buildings' horizontal stack bar chart for 2015 and 2021 to start from the left side moving towards the right and the "commercial and public services" buildings' horizontal stack bar chart for 2015 and 2021 to start from the right side moving towards the left. I want to have the graphs for 2015 to be in front of each other and the graphs from 2021 to be in front of each other. I want to have two horizontal axis, one from right to left and one from left to right.
Would it be possible to modify the code?
With regards
Shams

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by