0

嗨,我在 Matlab 中有以下代码

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])

我正在尝试绘制一个堆积条形图,显示每个条形的每个变量的颜色。但是,对于“AD_monthly_thermal_generation_250”值低于“CC_monthly_thermal_demand”的条形图,“AD_monthly_thermal_generation_250”颜色完全被“CC_monthly_thermal_demand”覆盖,因此我看不到这些值。有可能看到它们吗?

谢谢

4

1 回答 1

0

将输入组合在一起,使每个系列都是一列,然后使用选项'stack'

A = [495 500 500 195 210 100 70 65 85 265 320 430]';
B = [193 193 193 193 20  193 193 193 193 193 193 193]';
bar([B,A],'stacked')

编辑地址评论:

% Create random data and filler
A      = randi(100,10,1);
B      = randi(100,10,1);
mxA    = max(A);
filler = mxA-A;

% Plot stacked bar chart
h = bar([A,filler,B],'stacked');

% Set the filler to transparent
set(h(2),'Face','none','Edge','none')

% Set y-labels
yticks = linspace(0,max(B),5) + mxA;
set(gca,'Ytick', [linspace(0,mxA,5) yticks(2:end)],'YtickL', [linspace(0,mxA,5) yticks(2:end)-mxA])

在此处输入图像描述

于 2013-04-27T13:24:34.837 回答