本文介绍了Matlab中的3D堆叠条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想在一个'detached'
条形图中绘制多个堆叠的条形.例如,想象一下这完全是 bar 图,但是它是堆叠的,而不是一种单色的
I want to plot multiple stacked bar in only one 'detached'
bar plot. E.g, imagine this exactly bar plot, but stacked, instead of one single color.
推荐答案
% Set up two random data sets
data1=rand(10);
data2=rand(10);
% plot the first data set
bh=bar3(data1);
% Loop through each row and shift bars upwards
for i=1:length(bh)
zz = get(bh(i),'Zdata');
k = 1;
% Bars are defined by 6 faces(?), adding values from data2 will
% shift the bars upwards accordingly, I'm sure this could be made
% better!
for j = 0:6:(6*length(bh)-6)
zz(j+1:j+6,:)=zz(j+1:j+6,:)+data2(k,i);
k=k+1;
end
% Reset Zdata in chart
set(bh(i),'Zdata',zz);
end
% Set face colour to red for data1
set(bh,'FaceColor',[1 0 0]);
% Apply hold so that data2 can be plotted
hold on;
% Plot data2
bh=bar3(data2);
% Set face color to blue
set(bh,'FaceColor',[0 0 1]);
hold off;
这篇关于Matlab中的3D堆叠条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!