我想从表格中创建堆积条形图。这里有一个我正在查看的表格类型的 MWE:
clear all;
country1=rand(5,1);
country2=rand(5,1);
country3=rand(5,1);
country4=rand(5,1);
country5=rand(5,1);
date=1990:1994;
T=table(date',country1,country2,country3,country4,country5);
T.Properties.VariableNames{1}='date';
T.Total=sum(T{:,2:end},2);
T{:,2:end} = T{:,2:end}./T.Total;
A = table2array(T);
A(:,[1,end])=[];
A=sort(A,2);
TT=array2table(A,'VariableNames',{'country1','country2','country3','country4','country5'});
TT.Date=T.date;
TT.Total=T.Total;
T_new=table(TT.Date, TT.country1,TT.country2,TT.country3,TT.country4,TT.country5,TT.Total);
T_new.Properties.VariableNames=T.Properties.VariableNames;
T_new.World=sum(T{:,2:4},2);
T_new.World=1-(T_new.country4+T_new.country5);
T_new(:,[2:4,end-1])=[];
T_new
date country4 country5 World
____ ________ ________ _______
1990 0.2933 0.29471 0.41199
1991 0.31453 0.34511 0.34035
1992 0.22595 0.29099 0.48307
1993 0.26357 0.33336 0.40306
1994 0.28401 0.28922 0.42677
堆叠 BAR 的类型
=====================
根据T_new
表格,我想创建一个堆积条形图。在“x”轴上,图表应显示日期(1990、1991 等),每个日期应为一个堆叠条形图。因此,例如,1990
应该有一个条形图堆叠值0.2933 0.29471 0.41199
理想情况下,在堆栈栏中,我还希望包含 (country1, country2, world) 的标签以表示对应的值。
我如何在 matlab 中做到这一点?