Plotting multiple bar graphs

조회 수: 515(최근 30일)
Aftab Ahmed Khan
Aftab Ahmed Khan 2015년 4월 20일
댓글: Franciszek Aniol 2022년 3월 7일
Hi everyone, I am plotting 3 different bar graphs on a same figure window. I have managed up to this point, shown in the figure. I want them to be side by side not overlapping. Any help guys ?
hold on;
set(gca, 'XTick', 1:6, 'XTickLabel', labels);
title('Blocking Probability vs Routing Level');

채택된 답변

Star Strider
Star Strider 2015년 4월 20일
Guessing here because I don’t have all your data, but I would do something like this:
bpcombined = [bpcombine1(:), bpcombine2(:), bpcombine3(:)];
hb = bar(xdata, bpcombined, 'grouped')
You can then change the colours by referring to the individual bar series using the ‘hb’ handle. (The (:) creates each vector as a column vector so the concatenation works correctly.)
  댓글 수: 3
Wenbin Hou
Wenbin Hou 2017년 7월 12일
The answer is 'Change properties for a specific bar series by indexing into the object array'(I am taking it from the help file).
Actually if you go to help document of 'bar', you will see this example:
y = [2 4 6; 3 4 5]; b = bar(y); Then if you want to change the color and width of the second column, you can do this: b(2).LineWidth = 2; b(2).EdgeColor = 'red';

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Althaf V S
Althaf V S 2018년 12월 8일
% NOT an efficeint way,......BUT GOOD way to control all the elements of bar chart
ca = categorical({'SP5#1','SP5#2','SP6#Part 1B','SP6#Part 1C'});
hold on
hold on
hold on
title('PART D: Compare BASE SHEAR ');
legend('SP5#1','SP5#2','SP6#Part 1B','SP6#Part 1C');
ylabel('BASE SHEAR (Kips)');
  댓글 수: 1
Franciszek Aniol
Franciszek Aniol 2022년 3월 7일
I recommend this change to make it less tedious
ca = categorical({'SP5#1','SP5#2','SP6#Part 1B','SP6#Part 1C'});
value = [sp51bs sp52bs maxbssp6 maxbssp6c]
for n = 1:1:4 %could also use range of the vector called value as such 1:1:range(value)

댓글을 달려면 로그인하십시오.

Al in St. Louis
Al in St. Louis 2019년 5월 14일
It's really frustrating that bar insists on making a stacked graph, and there is literally no way to change it to grouped without mucking around creating a new matrix.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by