Combine three different set bar graphs in one graph

조회 수: 3 (최근 30일)
Prateek Gupta
Prateek Gupta 2018년 3월 26일
댓글: M 2018년 3월 28일
I have three sets of bar graphs. How can I just place them on one graph with some spacing between each set and with each set having a different colour? three sets are: 1) vector_22=[000,001,010,011,100,101,110,111] leak_22=[5.33,5.46,4.45,4.47,4.41,3.90,4.36,3.71]; bar(leak_22); set(gca, 'xticklabel',{'000','001','010','011','100','101','110','111'}); text(1:length(leak_22),leak_22,num2str(leak_22'),'vert','bottom','horiz','center'); xlabel('Input Vector Applied'); ylabel('Leakage in nW');
2) vector_32=[000,001,010,011,100,101,110,111] leak_32=[4.46,4.50,3.69,3.67,3.63,3.24,3.63,3.17]; bar(leak_32); set(gca, 'xticklabel',{'000','001','010','011','100','101','110','111'}); text(1:length(leak_32),leak_32,num2str(leak_32'),'vert','bottom','horiz','center'); xlabel('Input Vector Applied'); ylabel('Leakage in nW');
3) vector_45=[000,001,010,011,100,101,110,111] leak_45=[3.65,3.69,3.04,3.0,2.98,2.69,2.99,2.66]; bar(leak_45); set(gca, 'xticklabel',{'000','001','010','011','100','101','110','111'}); text(1:length(leak_45),leak_45,num2str(leak_45'),'vert','bottom','horiz','center'); xlabel('Input Vector Applied') ylabel('Leakage in nW')

답변 (1개)

M
M 2018년 3월 27일
You can group your 3 bar graphs using something like this:
b=bar([leak_22;leak_32;leak_45]);
For your example, you will have 3 groups of 8 bars.
If you want 8 groups of 3 bars, use the transpose of your vectors.
You can then change the color of specific bar using:
b(1).FaceColor='blue';
You can also change the line style and others properties.
  댓글 수: 4
Prateek Gupta
Prateek Gupta 2018년 3월 27일
b=bar([leak_22;leak_32;leak_45]); with this command I'm getting 8 colours bar. But I want each set of 8 bars of 1 colour only. Thanks!
M
M 2018년 3월 28일

Try

leak_32=[4.46,4.50,3.69,3.67,3.63,3.24,3.63,3.17]'; 
leak_22=[5.33,5.46,4.45,4.47,4.41,3.90,4.36,3.71]'; 
leak_45=[3.65,3.69,3.04,3.0,2.98,2.69,2.99,2.66]'; 
b=bar3([leak_22 leak_32 leak_45]); 

And see if it corresponds to your needs.

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

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by