how to plot side by side bar chart on the same axis?

1 view (last 30 days)
I would like to have bar side by side for M1 on the left side of the figure and then likewise for M2 on the right side. M1 has 10 columns-so the plot be constructed in such a way that column 1 is aside with column 6 of M1. similarly, column 2 of M1 in comparison with column 7 of M1. I want the same for M2 but on the right side of the figure (i.e. there should be a gap between M1 and M2 dataset) see attached image as an example (i don't want bar stacked and have only two time periods correspond to M1 and M2). I tried the following but am not getting anywhere
M1 = -5 + (5+5)*rand(1,10);
M2= -5 + (5+5)*rand(1,10);
figure()
bar([M1(:,1:5);M1(:,6:10)])
hold on
yyaxis right
bar([M2(:,1:5);M2(:,6:10)])
  1 Comment
James Knowles
James Knowles on 4 Jan 2018
This in built function may be of some use https://au.mathworks.com/help/matlab/ref/subplot.html

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!