help with the formatting of a stacked bar chart

1 次查看(过去 30 天)
Hi I have the following code
CC_monthly_thermal_demand = [495 500 500 195 210 100 70 65 85 265 320 430]';
AD_monthly_thermal_generation_250 = [193 193 193 193 193 193 193 193 193 193 193 193]';
figure;
bar(1:12,AD_monthly_thermal_generation_250)
hold on
bar(1:12,CC_monthly_thermal_demand,'r')
set(gca,'XTickLabel',{'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',' Sep', 'Oct', 'Nov',' Dec'},'FontSize',18)
title('Seasonal Anaerobic Digestion (250kWe) Thermal Energy Supply to Demand - 2012','FontSize',22)
ylabel('Thermal Energy (MWhe)')
legend('250 kWth Supply','Thermal Energy Demand')
grid on
axis([0 13 0 600])
I am trying to plot a stacked bar chart that shows the colour of each variable for every bar. However, for the bars where the "AD_monthly_thermal_generation_250" is a lower value than the "CC_monthly_thermal_demand" the "AD_monthly_thermal_generation_250" colour is completely covered by the "CC_monthly_thermal_demand" and so I can't see these values. Is it possible to be able to see them?
Thank you

回答(1 个)

Zhang lu
Zhang lu 2013-4-28
编辑:Zhang lu 2013-4-28
You can add another bar of condition code as follow . The fourth data of your vectors are almost identical, you can use 'zoom in' button to see the detail.
CODE:
CC_monthly_thermal_demand = [495 500 500 195 210 100 70 65 85 265 320 430]';
AD_monthly_thermal_generation_250 = [193 193 193 193 193 193 193 193 193 193 193 193]';
figure;
bar(1:12,CC_monthly_thermal_demand,'r')
hold on
bar(1:12,AD_monthly_thermal_generation_250)
bar(1:12,CC_monthly_thermal_demand.*(CC_monthly_thermal_demand<=AD_monthly_thermal_generation_250),'r')
set(gca,'XTickLabel',{'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',' Sep', 'Oct', 'Nov',' Dec'},'FontSize',18)
title('Seasonal Anaerobic Digestion (250kWe) Thermal Energy Supply to Demand - 2012','FontSize',22)
ylabel('Thermal Energy (MWhe)')
legend('250 kWth Supply','Thermal Energy Demand')
grid on
axis([0 13 0 600])

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by