groupLabels = {'20'; '40'; '60'; '80'};
stackDataI(:,:,1) = [4.53 4.84 5.28;
stackDataI(:,:,2) = [3.39 3.63 3.96;
stackDataI(:,:,3) = [2.37 2.53 2.76;
NumGroupsPerAxis = size(stackDataI, 1);
NumStacksPerGroup = size(stackDataI, 2);
groupBins = 1:NumGroupsPerAxis;
groupOffset = MaxGroupWidth/NumStacksPerGroup;
hold on; grid on; box on;
for i=1:NumStacksPerGroup
Y = squeeze(stackDataI(:,i,:));
internalPosCount = i - ((NumStacksPerGroup+1) / 2);
groupDrawPos = (internalPosCount)* groupOffset + groupBins;
h(i,:) = bar(Y, 'stacked');
set(h(i,:),'BarWidth',groupOffset);
set(h(i,:),'XData',groupDrawPos);
set(h(1),'FaceColor',[0.00138953219082905,0.470736452061139,0.750347383047707]); set(h(2),'FaceColor',[0.340435386753126,0.650430754979157,0.835108846688282]); set(h(3),'FaceColor',[0.732746641963872,0.858355720240852,0.933186660490968]);
set(h(4),'FaceColor',[1,0.700416859657249,0.00138953219082905]); set(h(5),'FaceColor',[1,0.757804539138490,0.192681797128300]); set(h(6),'FaceColor',[1,0.883279295970357,0.610930986567856]);
set(h(7),'FaceColor',[0.800000000000000,0.360000000000000,0.360000000000000]); set(h(8),'FaceColor',[0.855210745715609,0.536674386289949,0.536674386289949]); set(h(9),'FaceColor',[0.910884668828161,0.714830940250116,0.714830940250116]);
set(gca,'XTickMode','manual');
set(gca,'XTick',1:NumGroupsPerAxis);
set(gca,'XTickLabelMode','manual');
set(gca,'XTickLabel',groupLabels);
set(gca,'TickLabelInterpreter', 'latex');
hx = xlabel('\textbf{Item}','FontWeight','bold','interpreter','latex','FontSize',12);
hy = ylabel('\textbf{Cost}','FontWeight','bold','interpreter','latex','FontSize',12);
hl1 = legend([h(1),h(2),h(3)],{'X-1','X-2','X-3'},'FontSize',12,'Location','NorthWest','interpreter','latex');
ah1=axes('position',get(gca,'position'),'visible','off');
hl2 = legend(ah1,[h(4),h(5),h(6)],{'Y-1','Y-2','Y-3'},'FontSize',12,'Location','NorthEast','interpreter','latex');
ah1=axes('position',get(gca,'position'),'visible','off');
hl3 = legend(ah1,[h(7),h(8),h(9)],{'Z-1','Z-2','Z-3'},'FontSize',12,'Location','NorthEast','interpreter','latex');