Align subplot x-axes
古いコメントを表示
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.

採用された回答
その他の回答 (1 件)
Ameer Hamza
2018 年 4 月 24 日
The axis handle gave a Position property which specifies its location on the figure. The property is defined as [left bottom width height] as described here. Since you are only interested in changing the left starting position and width of graph2 you just need to change 1st and 3rd element of graph2.Position. You can set these values according to your requirement. As an example
graph2.Position(1) = graph1.Position(1)-0.04; % you can experiment by changing 0.04 and 0.08
graph2.Position(3) = graph1.Position(3)+0.08; % unless you achieve desired result.
You can just add these two statements at end of your script. Here I am moving left starting position of graph2 a bit left as compared to graph1 and also changing its width so that the figure will expand symmetrically.
カテゴリ
ヘルプ センター および File Exchange で Axes Appearance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!