double y axis bar chart to have bars next to each other

조회 수: 3 (최근 30일)
Andrew Alkiviades
Andrew Alkiviades 2013년 9월 7일
hi I have plotted a double y axis bar chart with the code below. It seems that the bars are overlaying. I am trying to get the bars so that they are next to each other on the same x position
Any help would be appreciated!
Wind_monthly_speed = [4.76 3.99 3.43 3.68 5.71 7.09 5.56 5.43 5.4 4.9 3.88 4.53];
Solar_monthly = [5.87 6.52 6.99 6.45 5.6 4.84 5.17 5.66 5.85 5.9 5.29 5.41];
month = 1:1:12;
average_monthly_wind_density = 1.2;
wind_monthly_power = 0.5*average_monthly_wind_density.*(Wind_monthly_speed.^3);
figure;
x1 = 1:12;
y1 = wind_monthly_power;
y2 = Solar_monthly;
plotyy(x1,y1,x1,y2,'bar','bar')
  댓글 수: 4
dpb
dpb 2013년 9월 7일
That'll end up scaling them grossly anyway, why not simply multiply the one by 100 and annotate it to note the change?
How about pasting about half your data for somebody to play with?
Andrew Alkiviades
Andrew Alkiviades 2013년 9월 7일
thanks dpb I have updated the initial question above. I will have to use the vectors above, I cannot modify unfortunately

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

답변 (1개)

dpb
dpb 2013년 9월 7일
편집: dpb 2013년 9월 8일
Well, I think it's much more informative as
bar(x1', [y1' y2'])
but suit yourself. As a starting point try
ha=plotyy(x1-0.5,y1,x1+0.5,y2,'bar','bar');
set(ha,'xlim',[-1 14])
set(ha,'xtick',1:12)
Then get the handles of the bar objects and modify colors and width to enhance visibility, etc., etc., etc., ... as desired
ADDENDUM:
Rather than use +/-0.5, try +/-0.2 save the additional handles from the plotyy() call--
[hyy,hl,ho]=plotyy(x1-0.2,y1,x1+0.2,y2,'bar','bar');
set(hyy,'xlim',[-1 14],'xtick',1:12)
set(ho,'barwidth',0.4)
set(hl,'facecolor','r','barwidth',0.4)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by