Reputation: 3616
I want to make two bars in the same fig in matlab. Now, I have two separate bar charts, what I want to do is combining them in one chart but with different colors (eg red and blue) to differentiate between the two barcharts.
This is the two barcharts appearing:
what I want to do is something like this:
Below is the code I'm using so if anyone could please help me.
load('x640_Sensor_Lights_On_1000mm-pgms.mat');
uu=unique(n);
nn=histc(n, uu);
h=figure; bar(uu,nn/numel(n));
print(h, '-dpdf', 'x1000');
saveas(h,'x1000','fig');
load('k640_Sensor_Lights_On_1000mm-pgms.mat');
uu=unique(n);
nn=histc(n, uu);
h=figure; bar(uu,nn/numel(n));
print(h, '-dpdf', 'k1000');
saveas(h,'k1000','fig');
Upvotes: 2
Views: 1455
Reputation: 10686
You can check out the examples in bar()
and specifically about bar styles:
Upvotes: 2
Reputation: 43
Try inserting the line "hold on" before your code for the second bar graph and "hold off" after.
> load('x640_Sensor_Lights_On_1000mm-pgms.mat');
uu=unique(n);
nn=histc(n, uu);
h=figure; bar(uu,nn/numel(n));
print(h, '-dpdf', 'x1000');
saveas(h,'x1000','fig');
load('k640_Sensor_Lights_On_1000mm-pgms.mat');
uu=unique(n);
hold on;
nn=histc(n, uu);
h=figure; bar(uu,nn/numel(n));
print(h, '-dpdf', 'k1000');
saveas(h,'k1000','fig');
hold off;
Upvotes: 1