Group overlay bar chars using cell with three 10x5 double arrays

1 回表示 (過去 30 日間)
aryan ramesh
aryan ramesh 2021 年 7 月 23 日
コメント済み: Yazan 2021 年 7 月 23 日
I am trying to generate a bar chart using one cell with 3(10*5) random elements as it is illustrated in the ZIMBI.png image
My code is like this:
for i = 1:3
cell_part = abs (randn(10,5))
figure;
bar ( cell_part(1,:))
hold on
% figure;
bar ( cell_part(2,:))
hold on
% figure;
bar ( cell_part(3,:))
hold on
bar ( cell_part(4,:))
hold on
bar ( cell_part(5,:))
cell_total{i}(:,:) = cell_part;
end
figure;
bar(cell_total{1}(:,:)', 'group' )
hold on
bar(cell_total{3}(:,:)', 'group' )
hold on
bar(cell_total{2}(:,:)', 'group' )
hold on
% Unfortunatelly, this code generates the image Cakld.png :
How can I associate the cell position with the bar chart ?
  3 件のコメント
aryan ramesh
aryan ramesh 2021 年 7 月 23 日
Hi, Scott. Tks for replying to me. Tks for your advice related to the for a loop. I saw this stacked option, but I want overlapped data between the columns of my cell_part(10, 5). It seems that the stacket option put the data over the previous one
I rewrote my code.
for i = 1:3
cell_part = abs (randn(10,5))
cell_total{i}(:,:) = cell_part;
end
figure;
bar(cell_total{1}(:,:)', 'group' )
hold on
bar(cell_total{3}(:,:)', 'group' )
hold on
bar(cell_total{2}(:,:)', 'group' )
hold on
but, still no luck
Scott MacKenzie
Scott MacKenzie 2021 年 7 月 23 日
編集済み: Scott MacKenzie 2021 年 7 月 23 日
Still no luck with what? Please try to clarify what you are trying to do. Is the key issue just adding tick labels as in the example chart you posted? If so, just following instructions in @Yazan's answer.

サインインしてコメントする。

採用された回答

Yazan
Yazan 2021 年 7 月 23 日
編集済み: Yazan 2021 年 7 月 23 日
A very simple solution is to plot the data directly but after introducing matrices of zeros so that the bars look like they are grouped. See the example below.
clear, clc
close all
% toy data of size 10-by-5
data1 = randi(5, [10 5]);
data2 = randi(5, [10 5]);
data3 = randi(5, [10 5]);
% insert zero matrices
data = [data1; zeros(5, 5); data2; zeros(5, 5); data3];
% plot stacked bars normally
bar(data, 'stacked');
ax = gca;
ax.XTick = [5 20 35];
ax.XTickLabel = {'Data1', 'Data2', 'Data3'};
  8 件のコメント
aryan ramesh
aryan ramesh 2021 年 7 月 23 日
編集済み: aryan ramesh 2021 年 7 月 23 日
Perfect. Tks :)
Yazan
Yazan 2021 年 7 月 23 日
You're welcome, but don't forget to accept the answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by