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 に答える