我相信您可能正在寻找:
bar([a ;b]', 'stacked')
===编辑1 ===
仔细观察一下您的图形,您可能还会寻找一种不太常规的“堆叠”,可以通过将两个条叠加在一起来实现,例如:
a=(1:5)';
b=(5:-1:1)';
c = a;
c(b<=a)=nan;
figure;
subplot(1,2,1);
bar([a,b]);
subplot(1,2,2);
hold on;
bar(a,'b');
bar(b,'r');
bar(c,'b');
hold off
===编辑结束1 ===
===编辑2 ===
这是我在评论中建议的实现,以将该思想扩展到任意数量的系列。基本上,每一层(从最高到最小)都以循环的方式进行绘制(使用补丁)。尽管这不再是Matlab条形图(据我所知,由于不能通过uistack访问给定系列的独立水平条,所以它无法解决您的问题),但生成的图适合您的描述。
function testBarOverlay()
% data initialization
nbSeries = 8;
nbBars = 5;
xt = 1:nbBars;
data = rand( nbBars, nbSeries );
%draw (then erase) figure and get the characteristics of Matlab bars (axis, colors...)
figure;
h = bar( data( :, 1 ) );
width = get( h, 'barWidth' );
delete( h );
% sort in order to start painting the tallest bars
[ sdata, idx ] = sort( data, 2 );
% get the vertices of the different "bars", drawn as polygons
x = [ kron( xt, [1;1] ) - width / 2; kron( xt, [1;1] ) + width / 2 ];
% paint each layer, starting with the 'tallest' ones first
for i = nbSeries : -1 : 1
y = [ zeros( nbBars, 1 ), sdata( :, i ), sdata( :, i ), zeros( nbBars, 1 ) ]';
p = patch( x, y, 'b' );
set( p, 'FaceColor', 'Flat', 'CData', idx( :, i )' );
end
end
===编辑结束2 ===
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句