MATLAB Answers

Hello, i want to display separate (side by side) bar on one graph. below is my code but its display bars on single column. and image what i should do?

1 view (last 30 days)
khalil ur Rehman
khalil ur Rehman on 12 Jan 2019
Commented: dpb on 13 Jan 2019
clc;
clear all;
hold on;
Rank_N = [15678 10987 15243 3467 1234]; % New Values After Implementation
C1 = categorical ({'Google','Bing','Alxa','Yahoo Directory','DMOZ',});
h1 = bar (C1,Rank_N,'b','barwidth',0.3);
Rank_O = [1111 3456 13456 3345 1038]; % Old Values Before Implementation
C2 = categorical ({'Google','Bing','Alxa','Yahoo Directory','DMOZ',});
h2 = bar (C2,Rank_O,'r','barwidth',0.3);
xlabel('Search Engines');
ylabel('Link Rank');
title('Site Link Rank on Different Search Engines');
legend ('New Values', 'Old Values');
legend ('Location','northeast');
legend ('boxoff');rank.jpg

  0 Comments

Sign in to comment.

Accepted Answer

dpb
dpb on 12 Jan 2019
Edited: dpb on 12 Jan 2019
AMENDED:
Rank = [15678 10987 15243 3467 1234;
1111 3456 13456 3345 1038].';
C = categorical ({'Google','Bing','Alxa','Yahoo Directory','DMOZ',});
hBar=bar(C,Rank,'barwidth',0.3);
See doc bar for details on various types of bar graphs and the data orientation for grouped vis a vis stacked, etc., ...

  4 Comments

Show 1 older comment
dpb
dpb on 12 Jan 2019
Ah, shoot! I misremembered the proper orientation by recollection instead of checking myself...you need the categories by row; the cases by column -- transpose the Rank array. Oh, and BTW, remove the color argument or both variables will be the same color.
I updated Answer...but I'll note reading the doc clearly and looking at the examples would have explained the problem... :)
dpb
dpb on 13 Jan 2019
Use .FaceColor property of each bar handle...follow the documentation to the "OutputArguments" section and then the link to "Bar Properties"
Each of the two groups of bars is a bar object; there are two handles returned in your case so you'll have to set each of those individually or use the set notation with cell arrays to do as a group.
Named arguments in the bar argument list are expanded to apply to each bar object so they affect global properties of the plot, not the pieces thereof individually.

Sign in to comment.

More Answers (0)

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by