MATLAB: Align subplot x-axes

graphsubplot

Hi all, could someone please help me on how to align the scales?
% data data = rand(14,2); x = data(:,1); y = data(:,2);
% dates t1 = datetime(2016,5,13); t2 = datetime(2016,8,12); t = t1:calweeks(1):t2;
% plot h = figure; graph1 = subplot(2,1,1); plot(t,x,'b-o',t,y,'r-*'); graph1.XAxis.Limits = [t1 t2]; graph1.XAxis.TickValues = t'; graph1.XAxis.TickLabelFormat = 'MMM-dd'; xtickangle(45) % graph1.XAxis.Visible = 'off'; % axes('Color','none','XColor','none'); graph2 = subplot(2,1,2); bar(t,x-y);
I would like to have the axes aligned like shown in the graph but the panels to be equal size.
Thank-you in advance.

Best Answer

I found a solution, realizing later that i didn't fit the graph 2 axis like I did for graph 1, and it seems to have solved the issue. Best regards, Jeff
% data data = rand(14,2); x = data(:,1); y = data(:,2);
% dates t1 = datetime(2016,5,13); t2 = datetime(2016,8,12); t = t1:calweeks(1):t2;
% plot h = figure; graph1 = subplot(2,1,1); plot(t,x,'b-o',t,y,'r-*'); graph1.XAxis.Limits = [t1 t2]; graph1.XAxis.TickValues = t'; graph1.XAxis.TickLabelFormat = 'MMM-dd'; xtickangle(45) graph1.XAxis.Visible = 'off';
graph2 = subplot(2,1,2); bar(t,x-y); graph2.XAxis.Limits = [t1 t2]; graph2.XAxis.TickValues = t'; grap2.XAxis.TickLabelFormat = 'MMM-dd';