Reputation: 75
Is there a simple way with the bar function to get 2 datasets side-by-side and not overlapping?
dataset1 = (num1, num2, num3, num4)
bar(dataset1);
I get 4 bars in a plot. Now let's get...
dataset2 = (num5, num6, num7, num8)
bar (dataset1);
hold on;
bar (dataset2);
There are 8 bars, sure, but dataset2 overlaps dataset1. I want them to appear side-by-side, adjacent, with spaces between their little group and the next two values that are bars (simply, 4 sets of 2 bars). This should be simple because the datasets are on the same scale.... Does this make sense? I tried doing something that Shai suggested in a different thread, but merely subtracting or adding a value to dataset 1 or 2 during the bar function (bar dataset1+.5) doesn't help.
Upvotes: 1
Views: 2667
Reputation: 7751
A single bar
plot should do the trick with dataset1
and dataset2
embedded in a matrix.
The following code
dataset1 = rand(4,1);
dataset2 = rand(4,1)+1;
bar([dataset1 dataset2])
legend({'data1';'data2'});
produces
Upvotes: 2