Question

I want to plot bar plot in which bars are grouped like this:

enter image description here

I have tried this code but I am not getting this type of plot. Please guide me how can I generate plot like above:

 load Newy.txt;        
 load good.txt;  

 one = Newy(:,1);    
 orig = good(:,1);    


hold on
bar(one,'m');
bar(orig,'g');
hold off
set(gca,'XTickLabel',{'0-19','20-39','40-79','80-159','160-319','320-639','640-1279','1280-1500'})

In each text file there is a list of numbers. The list comprises of 8 values.

Was it helpful?

Solution 2

I got the way to achieve group bars:

I had to plot the data such that there are 8 groups of bars where each group consists of 3 bars.

For that I wrote the data in my each file like this:

Y = [30.9858    1.36816 38.6943
    0.655176    6.44236 13.1563
    1.42942     3.0947  0.621403
     22.6364    2.80378 17.1299
    0.621871    5.37145 1.87824
    0.876739    5.97647 3.80334
     40.6585    68.6757 23.0408
     2.13606    6.26739 1.67559

    ];
bar(Y)

OTHER TIPS

You can use histc to count the values within certain edges. To group bars you can collect them in a single matrix (with the values in each column).

edges = [0 20 40 80 160 320 640 1280 1501];
edLeg = cell(numel(edges)-1,1);
for i=1:length(edLeg)
    edLeg{i} = sprintf('%d-%d',edges(i),edges(i+1)-1);
end
n = histc([one,orig],edges);
bar(n(1:end-1,:));
set(gca,'XTickLabels',edLeg)
legend('One','Orig')

I used these as test data

one = ceil(1500.*rand(200,1));
orig = ceil(1500.*rand(200,1));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top