Stack three area plots - MATLAB
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi
I have the attached Excel file which contains the data for 1-base emissions 2-post REEE 3-Abatement.
I want to plot the base emissions on y-axis first versus the years on x-axis.
Then, the post-REEE and the Abatement emisisons should be plotted such that they 'eat' from the 'base' as shown in the figure for the similar data below:
Is there a way I can do that in MATLAB please ?
many thanks

채택된 답변
Star Strider
2021년 4월 12일
This approaches what you want, however there must be some sort of conservation metric or other sort of scaling necessary to get the plot to appear as you want it to appear. I must leave that to you, since I do not understand how the various emissions values are related. (I left the ‘TotalEmissions’ vector that I created in the code, in the event you want to use it.)
T1 = readtable('CCC_data_emissions.xlsx');
T2 = T1; % Duplicate & Save Original
TF1 = ismember(T2.years, T2.years_1); % Matching Years
T2.emissions_1(TF1) = T1.emissions_1(~isnan(T1.emissions_1)); % Matching Values
T2.emissions_2(TF1) = T1.emissions_2(~isnan(T1.emissions_2)); % Matching Values
TotalEmissions = T2.emissions+T2.emissions_1+T2.emissions_2;
figure
area(T1.years, [T2.emissions-T2.emissions_1-T2.emissions_2, T2.emissions_1, T2.emissions_2])
legend('Emissions','Emissions_1','Emissions_2', 'Location','NE')
.
댓글 수: 12
AHMED FAKHRI
2021년 4월 12일
편집: AHMED FAKHRI
2021년 4월 12일
Many thanks for your solution @Star Strider
You are right that I need to tweak the data a bit. I did as attached. However, I still do not get similar to the graph attached in my post. Let me explain to you what are these data:
1- The base emissions data represent the annual carbon emissions till 2050 without any intervention from us. However, that is not what we want, we want to reduce the emissions further beyond 85 million tonne at 2050 (last data point). This represents actually the total emissions expected till 2050.
2- Therefore, we use energy efficincy measures called 'post-REEE' to reduce the base line emisisons which then reduces the base from 85 Mt in 2050 to 59 Mt. However, that is stil not enough.
3- We use technlogies such as Hydrogen to reduce the emissions further form 59 to reach just 4 Mt by 2050 as seen in my attached 'updated' file. Now, we are good since 4Mt is very low compared to 85.
Therefore, I want to plot the base first, then post-REEE reduces the base, then the technologies reduces the post-REEE.
However, the code does not work with my new data yet.
many thanks
I can’t make it worked with the area function, since I can’t figure out how to calculate the necessary values from the data provided, however I can make it work with patch, so this will have to do —
T1 = readtable('CCC_data_emissions.xlsx');
T2 = T1; % Duplicate & Save Original
TF1 = ismember(T2.years, T2.years_1); % Matching Years
T2.emissions_1(TF1) = T1.emissions_1(~isnan(T1.emissions_1)); % Matching Values
T2.emissions_2(TF1) = T1.emissions_2(~isnan(T1.emissions_2)); % Matching Values
figure
patch([T2.years; flipud(T2.years)], [T2.emissions; flipud(T2.emissions_1)], 'r', 'FaceAlpha',0.5)
hold on
patch([T2.years; flipud(T2.years)], [T2.emissions_1; flipud(T2.emissions_2)],'g', 'FaceAlpha',0.5)
patch([T2.years; flipud(T2.years)], [T2.emissions_2; zeros(size(T2.years))],'b', 'FaceAlpha',0.5)
grid
xlim([min(T2.years) max(T2.years)])
xlabel('Years')
ylabel('Annual Emissions [MtCO_2e]')
legend('Emissions','Emissions_1','Emissions_2', 'Location','NE')
producing —

.
AHMED FAKHRI
2021년 4월 12일
Many thanks @Star Strider
That is good also, I don't yet quite understand from where the flutucations came in the output circled in red
plotting the same data in Excel gives normal lines as below.


My final effort —
T1 = readtable('CCC_data_emissions.xlsx');
T2 = T1; % Duplicate & Save Original
NCD = ~ismember(T2.years, T2.years_1); % No Common Data Logical Vector
yearsNCD = T2.years(NCD); % No Common Data Years
emissionsNCD = T2.emissions(NCD); % No Common Data Emissions
Lv = ~isnan(T2.years_1);
years_1 = T2.years_1(Lv);
years_2 = T2.years_2(Lv);
emissions_1 = T1.emissions_1(Lv); % Matching Values
emissions_2 = T1.emissions_2(Lv); % Matching Values
figure
patch([T2.years; flipud(years_1)], [T2.emissions; flipud(emissions_1)], 'r', 'FaceAlpha',0.5)
hold on
patch([years_1; flipud(years_1)], [emissions_1; flipud(emissions_2)],'g', 'FaceAlpha',0.5)
patch([years_2; flipud(years_2)], [emissions_2; zeros(size(years_1))],'b', 'FaceAlpha',0.5)
% patch([yearsNCD; flipud(yearsNCD)], [emissionsNCD; zeros(size(emissionsNCD))], 'r', 'FaceAlpha',0.1)
grid
xlim([min(T2.years) max(T2.years)])
xlabel('Years')
ylabel('Annual Emissions [MtCO_2e]')
legend('Emissions','Emissions_1','Emissions_2', 'Location','NE')
producing —

There are no data prior to 2022 for some of the columns, so that area is blank. There is no logical way to fill it.
AHMED FAKHRI
2021년 4월 12일
Many thanks @Star Strider for the efforts, I really appreictae it. I will certainly accept this answer.
I will also try to delete the data prior to 2022 or add for others from 2017.
Thanks again.
Star Strider
2021년 4월 12일
As always, my pleasure!
It may not be necessary to delete data prior to 2022, simply to decide on how to plot it. One option may be to use the ‘emissions’ data for ‘emissions_1’ and ‘emissions_2’ prior to 2022 (since the abatement efforts had not yet begun). I must leave that to you, since this is your project.
AHMED FAKHRI
2021년 4월 12일
Many thanks That’s a very good suggestion. I will try that the first thing in the morning
Star Strider
2021년 4월 12일
As always, my pleasure!
AHMED FAKHRI
2021년 4월 14일
편집: AHMED FAKHRI
2021년 4월 14일
Hi @Star Strider, after some data tidying, I have finally produced nearly the same figure with the 'area' function using the below simple code. Thanks also to you.
Can I ask if you know please how to add the 'arrows' or the 'numbers' as in the original figure?
Many thanks
Years=Finalbalancedscenzip{:,1};
Base=Finalbalancedscenzip{:,2};
post_REEE=Finalbalancedscenzip{:,3};
post_DEC=Finalbalancedscenzip{:,4};
figure
area(Years,Base)
xlim([min(Years) max(Years)])
xlabel('Years')
ylabel('Annual Emissions [MtCO_2e]')
hold on
area(Years,post_REEE)
hold on
area(Years,post_DEC)
legend('REEE Reductions','Deep Dec. Abatement','Remaining Emissions ', 'Location','NE')
Those are annotation objects, and notoriously difficult to work with because of the ways they are addressed in the plot using normalised coordinates. (Those coordinates and calculations creating them are absolutely not obvious, at least to me.)
I have been struggling with this for a while and cannot figure out how to correctly scale all the locations from the data in the plot so that they will appear where they should be.
I have been able to figure out for this figure only (as I plotted it) to place the x-position of the objects that scales correctly for all the years (here using 2020):
Ax = gca;
pos = Ax.Position;
x = 0.77*(2020 - min(Years)) / (max(Years)-min(Years)) + pos(1)
that works for all the year values in this data set, at least in the plot I created, and for 2020 only the y-values:
y1 = [0.550 0.850];
y2 = [0.500 0.110];
so the annotation for that year would be:
annotation('textarrow', [1 1]*x, y1, 'String',sprintf('%.1f',Base(Years==2020)))
annotation('arrow', [1 1]*x, y2)
I must leave it to you to experiment with the ‘y1’ and ‘y2’ values for the other years you want to plot. I will continue to work on this to see if I can come up with something more general (I cannot promise anything), however in the interests of time, will stop here for now.
AHMED FAKHRI
2021년 4월 14일
That is brilliant, many thanks for the efforts, I will also work from my side and update you if I managed to do it.
Star Strider
2021년 4월 14일
I very much appreciate your compliment!
As always, my pleasure!
추가 답변 (1개)
Jithin Nambiar J
2021년 4월 12일
If you can plot the y values and x values for the 3 different ranges. You can use
hold on
after the first plot and at the end of last plot use
hold off
댓글 수: 1
AHMED FAKHRI
2021년 4월 12일
Hi, thanks I know how to use hold on and off but I need to plot the y values first using one scale or be able to hide other scales
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
