Tak
Tak

Reputation: 3616

how to make two bars in the same fig Matlab

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:bar1bar2

what I want to do is something like this: wanted

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

Answers (2)

Oleg
Oleg

Reputation: 10686

You can check out the examples in bar() and specifically about bar styles:

enter image description here

Upvotes: 2

William
William

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

Related Questions