matlab - Matlab 中的 3D 堆积条

标签 matlab plot

我想在一个 'detached' 条形图中绘制多个堆叠条形图。例如,完全想象这 bar绘图,但堆叠,而不是一种单一的颜色。

enter image description here

最佳答案

enter image description here

% 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 - Matlab 中的 3D 堆积条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13156133/

相关文章:

image-processing - 在 MATLAB 中处理图像的一部分

matlab - 3D曲线拟合

R包 'biomod2'执行plot函数时找不到文件

python - 如何在不同的图上绘制数据集

python - 从 txt 文件创建 heatmap2d

Matlab UI 控制单元

在命令窗口或独立绘图中通过 LaTeX 进行 MATLAB 和数学方程式?

matlab - Matlab 中的精英主义?

r - 如何绘制堆积比例图?

python - 根据函数绘制 PatchCollection