문제

Hi I am trying to create a stacked bar chart in matlab but the output graph seems to be adding the first data set (AD_monthly_generation_250) to the second one (CC_monthly_demand_2012). How can I avoid this?

my code is

%% AD STACKED CC %%

AD_monthly_generation_250 = [186 186 186 186 186 186 186 186 186 186 186 186]';
CC_monthly_demand_2012 = [199.575 206.701 145.284 135.944 127.689 93.281 80.311 78.859 98.145 168.572 206.365 113.030]';


% Create a stacked bar chart using the bar function
figure;
bar(1:12, [ AD_monthly_generation_250 CC_monthly_demand_2012 ], 0.5, 'stack');


% Add title and axis labels
title('Seasonal Anaerobic Digestion (250kWe) Supply to Demand - 2012','FontSize',22);
 set(gca,'XTickLabel',{'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',' Sep',     'Oct', 'Nov',' Dec'},'FontSize',18)
 ylabel('Energy (MWh)');
도움이 되었습니까?

해결책

I think the 'stack' option works as is supposed to... Try this code, maybe it's what you wanted:

%% AD STACKED CC %%

AD_monthly_generation_250 = [186 186 186 186 186 186 186 186 186 186 186 186]';
CC_monthly_demand_2012 = [199.575 206.701 145.284 135.944 127.689 93.281 80.311 78.859 98.145 168.572 206.365 113.030]';

% Create a stacked bar chart using the bar function
figure;
% bar(1:12, [ AD_monthly_generation_250 CC_monthly_demand_2012 ], 0.5, 'stack');
bar(1:12, AD_monthly_generation_250, 0.5, 'b');
hold on;
bar(1:12, CC_monthly_demand_2012, 0.5, 'r');
hold off;

% Add title and axis labels
title('Seasonal Anaerobic Digestion (250kWe) Supply to Demand - 2012','FontSize',22);
 set(gca,'XTickLabel',{'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',' Sep',     'Oct', 'Nov',' Dec'},'FontSize',18)
 ylabel('Energy (MWh)');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top