2013-04-27 125 views
0

您好我有在Matlab情节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”完全覆盖,因此我看不到这些值。它能够看到它们吗?

谢谢

回答

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

enter image description here

+0

是p可以这样做,以便条形图的y值与“A”和“B”中的数字相对应。我认为你的建议确实显示了每个栏的两个值,但这些值并不代表“A”和“B”中的值。它的作用是在“B”之后开始计算“A”,所以你得到了条形顶部= A + B – user643469 2013-04-27 13:28:25

+0

感谢你的建议 - 看起来相当不错。请让我知道,如果我问的是不可能的(在一个图表上有条)。 – user643469 2013-04-27 13:45:35

+0

你的意思是把酒吧**分组**吗?像在酒吧([A,B])? – Oleg 2013-04-27 13:46:30