combining multiple bar graph
조회 수: 2 (최근 30일)
이전 댓글 표시
I have 4 bar graphs. How to combine them into one graph.
It should look loke a 3D graph.
This is the code.
data{i} has 4 cells each of dimension 24x13.
for i = 1:4
data{i} = xlsread(filename,i);
figure
bar3(data{i},'stacked')
end
댓글 수: 0
답변 (1개)
ag
2024년 9월 25일
Hi Nethravathi,
To combine multiple 3D bar graphs into a single figure, you can use the bar3 function and manipulate the positions of each set of bars to ensure they don't overlap.
The below code snippet demonstrates how to achieve this, using dummy data:
% Number of datasets
numDatasets = 4;
% Dimensions of each dataset
numRows = 24;
numCols = 13;
% Generate random data for each dataset
data = cell(1, numDatasets);
for i = 1:numDatasets
data{i} = rand(numRows, numCols); % Replace this with your actual data
end
% Create a new figure
figure;
hold on; % This allows multiple plots in the same figure
% Define an offset for each dataset to prevent overlap
offset = 2; % Adjust this value to change the spacing between datasets
% Plot each dataset using bar3
for i = 1:numDatasets
% Adjust the x-position of each dataset
xOffset = (i - 1) * (numCols + offset);
% Plot the 3D bar graph with an offset
bar3(data{i}, 'stacked');
% Adjust the XData to offset the bars
h = get(gca, 'Children');
for j = 1:length(h)
xData = get(h(j), 'XData');
set(h(j), 'XData', xData + xOffset);
end
end
% Set axis labels
xlabel('Category');
ylabel('Group');
zlabel('Value');
% Set title
title('Combined 3D Bar Graph');
% Adjust viewing angle for better visualization
view(-30, 30);
% Release the hold on the current figure
hold off;
For more details, please refer to the following MathWorks documentation: bar3 - https://www.mathworks.com/help/matlab/ref/bar3.html
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Directed Graphs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!