How to plot multiple bar in one figure?
1 view (last 30 days)
Show older comments
Hi I encounter some problem while plotting the graph Here is my command :
This is the script for the data before shifting occured :
%Reading the data from the sheet 1, cells D2 to D30
dataMat=xlsread('TOFF','Sheet1','D2:D30');
% Get sum of numbers that satisfy the conditions for x-column
x1=sum(dataMat(:,1)<=1.0);
x2=sum((dataMat(:,1)>1.0) & (dataMat(:,1)<=2.0));
x3=sum((dataMat(:,1)>2.0) & (dataMat(:,1)<=3.0));
x4=sum((dataMat(:,1)>3.0) & (dataMat(:,1)<=4.0));
x5=sum((dataMat(:,1)>4.0)& (dataMat(:,1)<=5.0));
x6=sum(dataMat(:,1)>5.0);
% Create figure
figure1 = figure;
%Draw bar width =0.5 for readibility
bar ([x1 x2 x3 x4 x5 x6],0.8,'r');
%Rename x-axis to be more meaningful
set(gca,'XTickLabel',{'x<=1','1<x<=2','2<x<=3','3<x<=4','4<x<=5','x>5'});
xlabel('RL (mm)','FontSize',20);
ylabel('Number of people','FontSize',20);
title(' TOFF RL','FontSize',20);
set(gca,'FontSize',20);
This is script for data after shifting :
% Reading the data from the sheet 1, cells K2 to K30
dataMat2=xlsread('TOFF','Sheet 1','K2:K30');
% Get sum of numbers that satisfy the conditions for x-column
x1=sum(dataMat2(:,1)<=1.0);
x2=sum((dataMat2(:,1)>1.0) & (dataMat2(:,1)<=2.0));
x3=sum((dataMat2(:,1)>2.0) & (dataMat2(:,1)<=3.0));
x4=sum((dataMat2(:,1)>3.0) & (dataMat2(:,1)<=4.0));
x5=sum((dataMat2(:,1)>4.0)& (dataMat2(:,1)<=5.0));
x6=sum(dataMat2(:,1)>5.0);
% Create figure
figure1 = figure;
%Draw bar width =0.5 for readibility
bar ([x1 x2 x3 x4 x5 x6],0.8,'r');
%Rename x-axis to be more meaningful
set(gca,'XTickLabel',{'x<=1','1<x<=2','2<x<=3','3<x<=4','4<x<=5','x>5'});
xlabel('RL (mm)','FontSize',20);
ylabel('Number of people','FontSize',20);
title(' TOFF RL After','FontSize',20);
set(gca,'FontSize',20);
How to plot all these data into one figure/graph only?
I would like to have six group for x1 x2 x3 x4 x5 x6, and for each group containing 2 different color of bar graphs indicating before correction and after correction.
Please help. Thanks
0 Comments
Answers (1)
dpb
on 27 Dec 2016
...
edges=[1:5];
N=histc([dataMat1(:,1) dataMat2(:,1)],edges);
bar(N,0.8)
See doc for details for setting counting bins in histc or later histogram function and bar for details on how it works with arrays...
0 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!