Matlab:3D堆积条形图 [英] Matlab: 3D stacked bar chart
问题描述
我正在尝试创建一个3D堆积条形图,如下所示:
正如您所看到的,中心柱应该加起来高达380,但只有280高。其中一个数据集的条似乎被渲染到另外两个数据集中,这也解释了为什么条有3条中心分隔线,而不是我们预期的2条。
我使用的代码是:
core = bar3(test1);
set(core,'FaceColor',[1 0 0]); %红色
对于i = 1:长度(核心)
zz = get(core(i),'Zdata');
k = 1;
for j = 0:6:(6 * length(core)-6)
zz(j + 1:j + 6,:)= zz(j + 1:j + 6,:) + TEST2(K,I);
k = k + 1;
end
set(core(i),'Zdata',zz);
end
持有
core = bar3(test2);
set(core,'FaceColor',[0 1 1]);%青色
扣除
(对于i = 1):length(core)
zz = get(core(i),'Zdata');
k = 1;
for j = 0:6:(6 * length(core)-6)
zz(j + 1:j + 6,:)= zz(j + 1:j + 6,:) + TEST3(K,I);
k = k + 1;
end
set(core(i),'Zdata',zz);
结束
持有
core = bar3(test3);
set(core,'FaceColor',[1 1 0]);%yellow
hold off
如何让酒吧正确地向上移动?或者,我怎样才能使用Matlab代码为数据制作一个三维堆叠条形图?任何帮助非常感谢,感谢您的时间。
在第一个循环中使用:
$ (j + 1:j + 6,...)= zz(j + 1:j + 6,...)+ test2(k,i)+ test3( K,I);
而不是 zz(j + 1:j + 6,:)= zz(j + 1:j + 6,:)+ test2(k,i);
。
或者你可以使用相同的字符串在第二个循环中。
I'm trying to create a 3D stacked bar chart as in this question: 3D stacked bars in Matlab. However unlike that question I want to use 3 datasets instead of 2. I think I have a (probably simple) problem where the bars don't shift up correctly or something similar.
The three datasets I have are called test1, test2 and test3 and are respectively:
5 10 7
1 100 0
1 3 2
10 15 10
10 80 10
5 5 15
10 10 10
20 200 20
30 10 30
And plotting them produces this:
As you can see the central bar should add up to 380 but is only 280 tall. The bars for one of the datasets seem to be rendered "inside" the other two datasets, which would also explain why the bars have 3 central separation lines instead of the 2 we'd expect.
The code I'm using is:
core=bar3(test1);
set(core,'FaceColor',[1 0 0]); %red
for i=1:length(core)
zz=get(core(i),'Zdata');
k=1;
for j= 0:6:(6*length(core)-6)
zz(j+1:j+6,:)=zz(j+1:j+6,:)+test2(k,i);
k=k+1;
end
set(core(i),'Zdata',zz);
end
hold on
core=bar3(test2);
set(core,'FaceColor',[0 1 1]);%cyan
hold off
for i=1:length(core)
zz=get(core(i),'Zdata');
k=1;
for j= 0:6:(6*length(core)-6)
zz(j+1:j+6,:)=zz(j+1:j+6,:)+test3(k,i);
k=k+1;
end
set(core(i),'Zdata',zz);
end
hold on
core=bar3(test3);
set(core,'FaceColor',[1 1 0]);%yellow
hold off
How do I make the bars shift up properly? Or alternatively, how can I use Matlab code to make a 3D stacked bar chart for the data? Any help greatly appreciated, thanks for your time.
In the first loops use:
zz(j+1:j+6,:)=zz(j+1:j+6,:)+test2(k,i)+test3(k,i);
instead of zz(j+1:j+6,:)=zz(j+1:j+6,:)+test2(k,i);
.
Or you can use the same string in the second loops.
这篇关于Matlab:3D堆积条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!