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

2 次查看(过去 30 天)
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
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