MATLAB Answers

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

10 views (last 30 days)
Andrew Alkiviades
Andrew Alkiviades on 7 Sep 2013
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);
x1 = 1:12;
y1 = wind_monthly_power;
y2 = Solar_monthly;


Show 1 older comment
Andrew Alkiviades
Andrew Alkiviades on 7 Sep 2013
thanks for your reply. I need the 2 axis because there is about a factor of 100 between the 2 vectors and they also use different units so i need the 2 axis
dpb on 7 Sep 2013
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 on 7 Sep 2013
thanks dpb I have updated the initial question above. I will have to use the vectors above, I cannot modify unfortunately

Sign in to comment.

Answers (1)

dpb on 7 Sep 2013
Edited: dpb on 8 Sep 2013
Well, I think it's much more informative as
bar(x1', [y1' y2'])
but suit yourself. As a starting point try
set(ha,'xlim',[-1 14])
Then get the handles of the bar objects and modify colors and width to enhance visibility, etc., etc., etc., ... as desired
Rather than use +/-0.5, try +/-0.2 save the additional handles from the plotyy() call--
set(hyy,'xlim',[-1 14],'xtick',1:12)


Sign in to comment.

Sign in to answer this question.

Translated by