how to make two bars in the same fig Matlab

半世苍凉 提交于 2019-12-23 23:47:48

问题


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');

回答1:


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




回答2:


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; 


来源:https://stackoverflow.com/questions/16312749/how-to-make-two-bars-in-the-same-fig-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!