3D grouped bar-plots from 3D matrix
15 ビュー (過去 30 日間)
古いコメントを表示
I'm looking for a way to plot a 3D matrix (3x2x2) as a grouped 3D bar plot where each group has two different bars (according to the third dimension of the matrix). Please see the scratch below as a reference. Thanks
採用された回答
Mathieu NOE
2024 年 3 月 6 日
hello again
based on the comment / link above, this is what I can offer today
%generate somme dummy data
groups_x = 3;
rows_y = 2;
data = 2;
Y = rand(groups_x,rows_y,data);
% plot
figure(1);
hold on;
% define x spacing
x_spacing = 2;
% generate ticks / ticklabels
x_vector_ticks = (1:x_spacing:groups_x*x_spacing);
for ci = 1:length(x_vector_ticks)
XtickLabel{ci} = ['Group#' num2str(ci)];
end
y_vector_ticks = (1:rows_y);
for ci = 1:length(y_vector_ticks)
YtickLabel{ci} = ['Param#' num2str(ci)];
end
% main loop
for ci =1:groups_x
xval = 1+(ci-1)*x_spacing;
zval = squeeze(Y(ci,:,:));
h = bar3(zval,'grouped');
Xdat = get(h,'Xdata');
for ii=1:length(Xdat)
Xdat{ii}=Xdat{ii}+(xval-1)*ones(size(Xdat{ii}));
set(h(ii),'XData',Xdat{ii});
end
end
% set ticks / ticklabels
xticks(x_vector_ticks);
xticklabels(XtickLabel);
yticks(y_vector_ticks);
yticklabels(YtickLabel);
xlim([0 groups_x*x_spacing+1 ]);
view(15,20);
title('Grouped Style')
3 件のコメント
Adam Danz
2024 年 3 月 7 日
You could probably adjust the DataAspectRatio to make the bars square at their base.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!